iOS 开发 高德-----POI 数据相关

关键词.jpg

以下为获取POI 数据的一些方法,记录一下。

搜索类

  AMapSearchAPI *search = [[AMapSearchAPI alloc] init];
    search.delegate = self;
  • 根据关键词搜索
 关键字检索的请求参数类为 AMapPOIKeywordsSearchRequest,其中 keywords 是必设参数。types 为搜索类型
 AMapPOIKeywordsSearchRequest *request = [[AMapPOIKeywordsSearchRequest alloc] init];
   request.keywords            = @"北京大学";
//    request.city                = @"北京";
  request.types               = @"高等院校";
//    //是否返回扩展信息
//    request.requireExtension    = YES;
//
//    /*  搜索SDK 3.2.0 中新增加的功能,只搜索本城市的POI。*/
//    request.cityLimit           = YES;
//    ///是否返回子POI,默认为 NO。
//    request.requireSubPOIs      = YES;
调用 AMapSearchAPI 的 AMapPOIKeywordsSearch 并发起关键字检索。
//    [self.search AMapPOIKeywordsSearch:request];
  • 根据ID搜索
  AMapPOIIDSearchRequest *request = [[AMapPOIIDSearchRequest alloc] init];
    //POI全局唯一ID
    request.uid                 = uid;
    request.requireExtension    = YES;
 [self.search AMapPOIIDSearch:request];
  • 根据中心点坐标来搜周边的POI
 AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init];
    
    request.location            = [AMapGeoPoint locationWithLatitude:39.990459 longitude:116.481476];
    request.keywords            = @"电影院";
    /* 按照距离排序. */
    request.sortrule            = 0;
    request.requireExtension    = YES;
 [self.search AMapPOIAroundSearch:request];
  • 在指定的范围内搜索POI.(多边型搜索)
 NSArray *points = [NSArray arrayWithObjects:
                       [AMapGeoPoint locationWithLatitude:39.990459 longitude:116.481476],
                       [AMapGeoPoint locationWithLatitude:39.890459 longitude:116.581476],
                       nil];
    /**
     * @brief 实例化一个多边形对象
     * @param points 坐标集, AMapGeoPoint 数组
     */
    AMapGeoPolygon *polygon = [AMapGeoPolygon polygonWithPoints:points];
    
    AMapPOIPolygonSearchRequest *request = [[AMapPOIPolygonSearchRequest alloc] init];
    //多边形
    request.polygon             = polygon;
    request.keywords            = @"Apple";
    request.requireExtension    = YES;
 [self.search AMapPOIPolygonSearch:request];

以上四种(关键字 周边搜索 多边形搜索 ID 搜索)的回调(来自官方demo)

- (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response
{
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];
    }
    

}
  • 获取道路沿途的POI
 AMapRoutePOISearchRequest *request = [[AMapRoutePOISearchRequest alloc] init];
    ///起点坐标
    ///AMapGeoPoint 经纬度类
    request.origin = [AMapGeoPoint locationWithLatitude:self.startCoordinate.latitude longitude:self.startCoordinate.longitude];
    ///终点坐标
    request.destination = [AMapGeoPoint locationWithLatitude:self.destinationCoordinate.latitude longitude:self.destinationCoordinate.longitude];
    
    request.strategy = self.strategy;
    request.searchType = self.segmentControl.selectedSegmentIndex;
发起沿途搜索
[self.search AMapRoutePOISearch:request];

沿途搜索回调

/* 沿途搜索回调. */
- (void)onRoutePOISearchDone:(AMapRoutePOISearchRequest *)request response:(AMapRoutePOISearchResponse *)response
{
    
    if (response.pois.count == 0)
    {
        return;
    }

}
  • 提示语
AMapInputTipsSearchRequest *tips = [[AMapInputTipsSearchRequest alloc] init];
    tips.keywords = key;
    tips.city     = @"北京";
 [self.search AMapInputTipsSearch:tips];

输入提示回调

/* 输入提示回调. */
- (void)onInputTipsSearchDone:(AMapInputTipsSearchRequest *)request response:(AMapInputTipsSearchResponse *)response
{
    if (response.count == 0)
    {
        return;
    }
    
    [self.tips setArray:response.tips];
    [self.tableView reloadData];
   
}

根据提示语进行的后续操作(来自官方demo)

  相关类 AMapTip 输入提示类
     AMapTip *tip = self.tips[indexPath.row];

/* 清除annotations & overlays */
- (void)clear
{
    [self.mapView removeAnnotations:self.mapView.annotations];
    [self.mapView removeOverlays:self.mapView.overlays];
}
//1)uid为空,location为空,该提示语为品牌词,可根据该品牌词进行POI关键词搜索。
//2)uid不为空,location为空,为公交线路,根据uid进行公交线路查询。
//3)uid不为空,location也不为空,是一个真实存在的POI,可直接显示在地图上。
- (void)clearAndShowAnnotationWithTip:(AMapTip *)tip
{
    /* 清除annotations & overlays */
    [self clear];
    
    if (tip.uid != nil && tip.location != nil) /* 可以直接在地图打点  */
    {
        AMapTipAnnotation *annotation = [[AMapTipAnnotation alloc] initWithMapTip:tip];
        [self.mapView addAnnotation:annotation];
        [self.mapView setCenterCoordinate:annotation.coordinate];
        [self.mapView selectAnnotation:annotation animated:YES];
    }
    else if (tip.uid != nil && tip.location == nil)/* 公交路线,显示出来*/
    {
        AMapBusLineIDSearchRequest *request = [[AMapBusLineIDSearchRequest alloc] init];
        request.city                        = @"北京";
        request.uid                         = tip.uid;
        request.requireExtension            = YES;
        
        [self.search AMapBusLineIDSearch:request];
    }
    else if(tip.uid == nil && tip.location == nil)/* 品牌名,进行POI关键字搜索 */
    {
        AMapPOIKeywordsSearchRequest *request = [[AMapPOIKeywordsSearchRequest alloc] init];
        
        request.keywords         = tip.name;
        request.city             = @"北京";
        request.requireExtension = YES;
        [self.search AMapPOIKeywordsSearch:request];
    }
}
// 已方法衍生的一些回调和后续操作  看官方文档
  • 搜索错误回调
- (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error
{
   NSLog(@"Error: %@ - %@", error, [ErrorInfoUtility errorDescriptionWithCode:error.code]);
}

编码与反编码( AMapSearchAPI *search ,AMapSearchAPI必须全局!!!!)

-地理编码

 AMapGeocodeSearchRequest *geo = [[AMapGeocodeSearchRequest alloc] init];
    geo.address = @"环球中心";
  // 调用 AMapSearchAPI 的 AMapGeocodeSearch 并发起地理编码。
    [self.search AMapGeocodeSearch:geo];

地理编码回调

- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response
{
    if (response.geocodes.count == 0)
    {
        return;
    }
    
//    NSMutableArray *annotations = [NSMutableArray array];
//
//    [response.geocodes enumerateObjectsUsingBlock:^(AMapGeocode *obj, NSUInteger idx, BOOL *stop) {
//        GeocodeAnnotation *geocodeAnnotation = [[GeocodeAnnotation alloc] initWithGeocode:obj];
//        [annotations addObject:geocodeAnnotation];
//    }];
//
//    if (annotations.count == 1)
//    {
//        [self.mapView setCenterCoordinate:[annotations[0] coordinate] animated:YES];
//    }
//    else
//    {
//        [self.mapView setVisibleMapRect:[CommonUtility minMapRectForAnnotations:annotations]
//                               animated:YES];
//    }
//
//    [self.mapView addAnnotations:annotations];
//

  NSLog(@"*******%f*******%f",[annotations[0] coordinate].latitude,[annotations[0] coordinate].longitude);
}

地理反编码

    //反编码
    AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];
    
    regeo.location                    = [AMapGeoPoint locationWithLatitude:coordinate.latitude longitude:coordinate.longitude];
    regeo.requireExtension            = YES;
    
    [self.search AMapReGoecodeSearch:regeo];

地理反编码回调


/* 逆地理编码回调. */
- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response
{
    if (response.regeocode != nil && _isSearchFromDragging == NO)
    {
        CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(request.location.latitude, request.location.longitude);
        ReGeocodeAnnotation *reGeocodeAnnotation = [[ReGeocodeAnnotation alloc] initWithCoordinate:coordinate
reGeocode:response.regeocode];
        [self.mapView addAnnotation:reGeocodeAnnotation];
        [self.mapView selectAnnotation:reGeocodeAnnotation animated:YES];
        //返回具体位置
        NSString * str =[NSString stringWithFormat:@"%@%@%@%@",reGeocodeAnnotation.reGeocode.addressComponent.province,reGeocodeAnnotation.reGeocode.addressComponent.city,reGeocodeAnnotation.reGeocode.addressComponent.district,reGeocodeAnnotation.reGeocode.addressComponent.towncode];
        NSLog(@"======%@",str);
        
    }
    else /* from drag search, update address */
    {
        [self.annotation setAMapReGeocode:response.regeocode];
        [self.mapView selectAnnotation:self.annotation animated:YES];
    }
}

落叶的位置 谱出一首诗
时间在消逝 我们的故事开始
这是第一次
让我见识爱情 可以慷慨又自私
你是我的关键词
--------林俊杰《关键词》

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,117评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,328评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,839评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,007评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,384评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,629评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,880评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,593评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,313评论 1 243
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,575评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,066评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,392评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,052评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,082评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,844评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,662评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,575评论 2 270