自2018年10月18日起,高德开发者论坛除车机板块外,其他板块将停止发帖与维护,如您有使用问题请 提交工单 联系我们,感谢您的理解。

查看: 5051|回复: 0
打印 上一主题 下一主题

iOS SDK 旧版服务升级新版攻略

[复制链接]
最佳答案
2 

12

主题

38

帖子

218

积分

超级版主

Rank: 8Rank: 8

积分
218
跳转到指定楼层
楼主
发表于 2014-12-11 15:15:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 luzerner 于 2014-12-11 15:21 编辑

iOSV2.0.6.1(含)之前版本的SDK对应的地图和搜索服务(poi查询、逆地理编码、路径规划等)将于2015年2月底停止使用。采用旧版服务的开发者需要尽快进行SDK的升级。
注意:升级之后,工程配置方法和地图的部分接口也有变动,这个可参考现在官网的开发指南,地址为http://lbs.amap.com/api/ios-sdk/guide/mapview/
特别注意:升级到新版本是要重新申请Key的,申请方法请参考:http://lbs.amap.com/api/ios-sdk/guide/verify/
以下是搜索代码的升级方案
1.     先从http://lbs.amap.com/api/ios-sdk/down/下载SDK(搜索库和地图库是分开的),其中2.3.0版本是32位版本的SDK,2.4.0版本是64位版本的SDK,可根据自身的app的要求进行选择
2.     将framework添加到工程中,参考:http://lbs.amap.com/api/ios-sdk/guide/project/
3.     代码更新,更新步骤:
1) 头文件中引入#import <AMapSearchKit/AMapSearchAPI.h>   //2.0.6.1#import "MASearchKit.h"
2) 继承AMapSearchDelegate协议   // 2.0.6  MASearchDelegate
3) 定义search对象 @property(nonatomic, strong) AMapSearchAPI *search; //2.0.6.1 @property (nonatomic,strong) MASearch *search;
4) 构造search对象,传入申请的Key self.search = [[AMapSearchAPI alloc]initWithSearchKey: @"您的key" Delegate:self];
5) 进行搜索查询

设置查询参数,进行POI查询
  1. AMapPlaceSearchRequest *poiRequest =  [[AMapPlaceSearchRequest alloc] init];
  2.   
  3. poiRequest.searchType =  AMapSearchType_PlaceKeyword;
  4.   
  5. poiRequest.keywords = @"俏江南";
  6.   
  7. poiRequest.city =  @[@"beijing"];
  8.   
  9. ////周边
  10.   
  11. //poiRequest.location = [AMapGeoPoint locationWithLatitude:39.990459  longtitude:116.481476];
  12.   
  13. //poiRequest.radius= 1000;
  14.   
  15. poiRequest.requireExtension = YES;
  16.   
  17. [self.search AMapPlaceSearch:  poiRequest];
复制代码


查询回调
  1. -  (void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request  response:(AMapPlaceSearchResponse *)response
  2.   
  3. {
  4.   
  5.   NSString *strCount =  [NSString stringWithFormat:@"count: %d",response.count];
  6.   
  7.   NSString *strSuggestion =  [NSString stringWithFormat:@"Suggestion: %@", response.suggestion];
  8.   
  9.   NSString *strPoi =  @"";
  10.   
  11.   for (AMapPOI *p in response.pois)  {
  12.   
  13.     strPoi =  [NSString stringWithFormat:@"%@\nPOI: %@", strPoi, p.description];
  14.   
  15.   }
  16.   
  17.   NSString *result = [NSString  stringWithFormat:@"%@ \n %@ \n %@", strCount, strSuggestion,  strPoi];
  18.   
  19.   NSLog(@"Place: %@",  result);
  20.   
  21. }
复制代码




发起路径规划查询
  1. AMapNavigationSearchRequest  *naviRequest= [[AMapNavigationSearchRequest alloc] init];
  2.   
  3. naviRequest.searchType =  AMapSearchType_NaviDrive;//路径规划类型,驾车、步行、公交
  4.   
  5. naviRequest.requireExtension = YES;
  6.   
  7. naviRequest.origin = [AMapGeoPoint  locationWithLatitude:39.994949 longitude:116.447265]; //起点
  8.   
  9. naviRequest.destination  = [AMapGeoPoint locationWithLatitude:39.990459 longitude:116.481476];//终点
  10.   
  11. [self.search AMapNavigationSearch:  naviRequest];
复制代码

查询回调
  1. - (void)onNavigationSearchDone:(AMapNavigationSearchRequest  *)request response:(AMapNavigationSearchResponse *)response
  2.   
  3. {
  4.   
  5.   NSString *result = [NSString  stringWithFormat:@"Navi: %@", response.route.description];
  6.   
  7.   NSLog(@"%@",  result);
  8.   
  9. }
复制代码

l  地理&逆地理


以逆地理为例
设置参数,进行逆地理查询
  1. - (void)searchReGeocode
  2.   
  3. {
  4.   
  5.   AMapReGeocodeSearchRequest *regeoRequest  = [[AMapReGeocodeSearchRequest alloc] init];
  6.   
  7.   regeoRequest.searchType =  AMapSearchType_ReGeocode;
  8.   
  9.   regeoRequest.location =  [AMapGeoPoint locationWithLatitude:39.990459 longtitude:116.481476];
  10.   
  11.   regeoRequest.radius = 10000;
  12.   
  13.   regeoRequest.requireExtension  = YES;
  14.   
  15.   [self.search  AMapReGoecodeSearch: regeoRequest];
  16.   
  17. }
复制代码

实现回调,获取查询结果:
  1. -  (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request  response:(AMapReGeocodeSearchResponse *)response
  2.   
  3. {
  4.   
  5.   NSString *result = [NSString stringWithFormat:@"ReGeocode:  %@", response.regeocode];
  6.   
  7.   NSLog(@"ReGeo: %@",  result);
  8.   
  9. }
复制代码

输入提示
      
以上所有的功能都提供demo,下载地址:http://lbs.amap.com/api/ios-sdk/down/


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|小黑屋|高德开发者论坛

Copyright ©2014 高德开发者论坛.All Rights Reserved |京ICP证070711号

意见反馈 常见问题 服务条款 联系我们
快速回复 返回顶部 返回列表