本帖最后由 luzerner 于 2014-12-11 15:21 编辑
iOSV2.0.6.1(含)之前版本的SDK对应的地图和搜索服务(poi查询、逆地理编码、路径规划等)将于2015年2月底停止使用。采用旧版服务的开发者需要尽快进行SDK的升级。 以下是搜索代码的升级方案 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查询 - AMapPlaceSearchRequest *poiRequest = [[AMapPlaceSearchRequest alloc] init];
-
- poiRequest.searchType = AMapSearchType_PlaceKeyword;
-
- poiRequest.keywords = @"俏江南";
-
- poiRequest.city = @[@"beijing"];
-
- ////周边
-
- //poiRequest.location = [AMapGeoPoint locationWithLatitude:39.990459 longtitude:116.481476];
-
- //poiRequest.radius= 1000;
-
- poiRequest.requireExtension = YES;
-
- [self.search AMapPlaceSearch: poiRequest];
复制代码
查询回调 - - (void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse *)response
-
- {
-
- NSString *strCount = [NSString stringWithFormat:@"count: %d",response.count];
-
- NSString *strSuggestion = [NSString stringWithFormat:@"Suggestion: %@", response.suggestion];
-
- NSString *strPoi = @"";
-
- for (AMapPOI *p in response.pois) {
-
- strPoi = [NSString stringWithFormat:@"%@\nPOI: %@", strPoi, p.description];
-
- }
-
- NSString *result = [NSString stringWithFormat:@"%@ \n %@ \n %@", strCount, strSuggestion, strPoi];
-
- NSLog(@"Place: %@", result);
-
- }
复制代码
发起路径规划查询 - AMapNavigationSearchRequest *naviRequest= [[AMapNavigationSearchRequest alloc] init];
-
- naviRequest.searchType = AMapSearchType_NaviDrive;//路径规划类型,驾车、步行、公交
-
- naviRequest.requireExtension = YES;
-
- naviRequest.origin = [AMapGeoPoint locationWithLatitude:39.994949 longitude:116.447265]; //起点
-
- naviRequest.destination = [AMapGeoPoint locationWithLatitude:39.990459 longitude:116.481476];//终点
-
- [self.search AMapNavigationSearch: naviRequest];
复制代码
查询回调 - - (void)onNavigationSearchDone:(AMapNavigationSearchRequest *)request response:(AMapNavigationSearchResponse *)response
-
- {
-
- NSString *result = [NSString stringWithFormat:@"Navi: %@", response.route.description];
-
- NSLog(@"%@", result);
-
- }
复制代码
l 地理&逆地理
以逆地理为例 设置参数,进行逆地理查询 - - (void)searchReGeocode
-
- {
-
- AMapReGeocodeSearchRequest *regeoRequest = [[AMapReGeocodeSearchRequest alloc] init];
-
- regeoRequest.searchType = AMapSearchType_ReGeocode;
-
- regeoRequest.location = [AMapGeoPoint locationWithLatitude:39.990459 longtitude:116.481476];
-
- regeoRequest.radius = 10000;
-
- regeoRequest.requireExtension = YES;
-
- [self.search AMapReGoecodeSearch: regeoRequest];
-
- }
复制代码
实现回调,获取查询结果: - - (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response
-
- {
-
- NSString *result = [NSString stringWithFormat:@"ReGeocode: %@", response.regeocode];
-
- NSLog(@"ReGeo: %@", result);
-
- }
复制代码
输入提示
|