高德地土提示搜索 AMapTip

先添加一个搜索框:

 _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 44)];
    _searchBar.delegate = self;
    [self.view addSubview:_searchBar];

简单的apikey自己在高德申请

 [AMapSearchServices sharedServices].apiKey = MAP_KEY;

    //初始化检索对象
    _searchArr = [[AMapSearchAPI alloc] init];

    _searchArr.delegate = self;

然后执行搜索框的代理方法:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    NSLog(@"%f",[UIApplication sharedApplication].keyWindow.frame.size.height);
    flagSearched = NO;
    return YES;
}

//输入提示的搜索  这是重点  因为提示的时候是在你输入变化的时候进行数据提示的
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    AMapInputTipsSearchRequest *tipsSearch = [[AMapInputTipsSearchRequest alloc] init];
    _collectionV.hidden = YES;
    if (searchBar.text.length < 1) {
        _collectionV.hidden = NO;
    }

//搜索的关键字:

    tipsSearch.keywords = searchText;

.//这个是搜索的限制城市:

    tipsSearch.city = self.parkCity;

//搜索的关键代码然后会执行搜索回调:见下面的代理方法!

    [_searchArr AMapInputTipsSearch:tipsSearch];
}


/* 输入提示回调. */
- (void)onInputTipsSearchDone:(AMapInputTipsSearchRequest *)request response:(AMapInputTipsSearchResponse *)response
{
    [self.arrResults setArray:response.tips];
    [self.tbSearchResults reloadData];
}

AMapInputTipsSearchResponse:有两个属性:

@property (nonatomic, assign) NSInteger count; //!< 返回数目
@property (nonatomic, strong) NSArray *tips; //!< 提示列表 AMapTip 数组

AMapTip:

@property (nonatomic, copy) NSString *uid; //!< poi的id
@property (nonatomic, copy) NSString *name; //!< 名称
@property (nonatomic, copy) NSString *adcode; //!< 区域编码
@property (nonatomic, copy) NSString *district; //!< 所属区域
@property (nonatomic, copy) AMapGeoPoint *location; //!< 位置



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值