Rumah > Soal Jawab > teks badan
我这里添加了高德地图的搜索代码,地图页面上,不显示搜索结果,初始化代码如下, //初始化检索对象
_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);
}