_searchApi = [[AMapSearchAPI alloc] initWithSearchKey:MAP_APIKEY Delegate:self];
_poiRequest = [[AMapPlaceSearchRequest alloc] init];
//点击照片出现周边搜索信息
AMapGeoPoint *searchPoint =[AMapGeoPoint locationWithLatitude:
_LocationCoordinate.latitude
longitude:_LocationCoordinate.longitude];
_poiRequest.searchType = AMapSearchType_PlaceAround;//搜索的类型为周边搜索
NSArray *arr = [NSArray arrayWithObjects:@"住宿服务",@"汽车服务",@"餐饮服务",
@"地名地址信息"@"科教文化服务",@"风景名胜", nil];
_poiRequest.types = arr; //搜索的内容
_poiRequest.offset = 120; //每页搜索的信息个数
_poiRequest.location = searchPoint; //搜索的中心点
_searchApi.delegate = self;
_poiRequest.radius = 5000; //搜索半径
_poiRequest.sortrule = 1; //结果以远近排序
//发起POI搜索
[_searchApi AMapPlaceSearch:_poiRequest];//发起请求搜索
pragma mark - searchAPIDelegate--POI搜索的代理方法
- (void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse *)response
{
//增加默认地址还是搜索列表地址判断,防止产生冲突而崩溃
if (_LocationCoordinate.longitude) {
[_searchLocationArrayData removeAllObjects];
NSMutableArray *array1 = [[NSMutableArray alloc] initWithCapacity:0];
NSMutableArray *array2 = [[NSMutableArray alloc] initWithCapacity:0];
if (response.count == 0) {
[_searchLocationArrayData addObject:_searchLocationName];
} else {
for (AMapPOI *p in response.pois) {
mapSearchResult *searchResult = [[mapSearchResult alloc] init];
searchResult.mapSearchResultTypePoi = p.type;
searchResult.mapSearchResultName = p.name;
searchResult.mapSearchResultCityDetail = [NSString stringWithFormat:
@"%@%@%@",p.city,p.district,p.address];
NSRange rang = [p.type rangeOfString:@";"];
NSString *strType = [p.type substringToIndex:rang.location];
if ([strType isEqualToString:@"风景名胜"]) {
[array1 addObject:searchResult];
} else {
[array2 addObject:searchResult];
}
}
}
//排序 将风景名胜放在最前面
for (mapSearchResult *map in array1) {
[_searchLocationArrayData addObject:map];
}
for (mapSearchResult *map in array2) {
[_searchLocationArrayData addObject:map];
}
if (_searchLocationArrayData.count != 1) {
_searchLocationTableView.hidden = NO;
[_addLocationButton removeFromSuperview];
[_lable removeFromSuperview];
[_searchLocationTableView reloadData];
} else {
[self addUserLocationWithImage];
}
}
}
网友评论