高德地圖POI搜索

_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];
    }
    }
    }
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容