ios sdk 高德地图的搜索在地图页面上,不显示搜索结果
高洛峰
高洛峰 2017-04-17 13:31:39
0
0
699

我这里添加了高德地图的搜索代码,地图页面上,不显示搜索结果,初始化代码如下, //初始化检索对象

_searchMapView = [[AMapSearchAPI alloc] initWithSearchKey:@"549f6a2bfd98c54aaf000c6f" Delegate:self];
if ([kCurentLanguage isEqualToString:@"en"]) {
    _searchMapView.language = AMapSearchLanguage_en;
}
else if ([kCurentLanguage isEqualToString:@"zh-Hans"]) {
    _searchMapView.language = AMapSearchLanguage_zh_CN;
}
//构造AMapPlaceSearchRequest对象,配置关键字搜索参数
AMapPlaceSearchRequest *poiRequest = [[AMapPlaceSearchRequest alloc] init];
poiRequest.searchType = AMapSearchType_PlaceKeyword;
poiRequest.keywords = @"俏江南";
poiRequest.city = @[@"beijing"];
poiRequest.requireExtension = YES;

//发起POI搜索
[_searchMapView AMapPlaceSearch: poiRequest];

获得搜索结果的回调代码如下:

//实现POI搜索对应的回调函数
- (void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse *)response
{
    if(response.pois.count == 0)
    {
        return;
    }

    //通过AMapPlaceSearchResponse对象处理搜索结果
    NSString *strCount = [NSString stringWithFormat:@"count: %ld",response.count];
    NSString *strSuggestion = [NSString stringWithFormat:@"Suggestion: %@", response.suggestion];
    NSString *strPoi = @"";
    for (AMapPOI *p in response.pois) {
        strPoi = [NSString stringWithFormat:@"%@\nPOI: %@", strPoi, p.description];
    }
    NSString *result = [NSString stringWithFormat:@"%@ \n %@ \n %@", strCount, strSuggestion, strPoi];
    NSLog(@"Place: %@", result);
}
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

membalas semua(0)
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan