music1983 / iOS-place-search

iOS-place-search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

本工程为基于高德地图iOS SDK进行封装,实现了兴趣点搜索的功能。

前述

功能描述

基于3D地图SDK和搜索SDK进行封装,通过搜索提示进行关键字提示,然后再进行兴趣点关键字查询。

核心类/接口

接口 说明 版本
AMapSearchAPI - (void)AMapInputTipsSearch:(AMapInputTipsSearchRequest *)request; 输入提示查询接口 v4.0.0
AMapSearchAPI - (void)AMapPOIKeywordsSearch:(AMapPOIKeywordsSearchRequest *)request; POI 关键字查询接口 v4.0.0

核心难点

/* 输入提示回调. */
- (void)onInputTipsSearchDone:(AMapInputTipsSearchRequest *)request response:(AMapInputTipsSearchResponse *)response
{
    if (response.count == 0)
    {
        return;
    }
    
    [self.tips setArray:response.tips];
    [self.tableView reloadData];
}
/* POI 搜索回调. */
- (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response
{
    [self.mapView removeAnnotations:self.mapView.annotations];
    
    if (response.pois.count == 0)
    {
        return;
    }
    
    NSMutableArray *poiAnnotations = [NSMutableArray arrayWithCapacity:response.pois.count];
    
    [response.pois enumerateObjectsUsingBlock:^(AMapPOI *obj, NSUInteger idx, BOOL *stop) {
        
        [poiAnnotations addObject:[[POIAnnotation alloc] initWithPOI:obj]];
        
    }];
    
    /* 将结果以annotation的形式加载到地图上. */
    [self.mapView addAnnotations:poiAnnotations];
    
    /* 如果只有一个结果,设置其为中心点. */
    if (poiAnnotations.count == 1)
    {
        [self.mapView setCenterCoordinate:[poiAnnotations[0] coordinate]];
    }
    /* 如果有多个结果, 设置地图使所有的annotation都可见. */
    else
    {
        [self.mapView showAnnotations:poiAnnotations animated:NO];
    }
}

About

iOS-place-search


Languages

Language:Objective-C 98.9%Language:Ruby 1.1%