您的位置:首页 > 其它

高德地图 正向地理编码 逆向地理编码

2016-07-06 09:23 435 查看
设置检索KEY的方法 : [AMapSearchServices sharedServices].apiKey
= apiKey;
-------------------------------------------------------------------------------------------------------
#pragma mark -- 正向地理编码 (根据地名定位当前位置)
Address 用户当前位置:
- (void)getDefaultUserLocationWithAddress:(NSString *)address {
    self.searchAPI = [[AMapSearchAPI alloc] init];  
    self.searchAPI.delegate = self;
    //构造AMapGeocodeSearchRequest对象,address为必选项,city为可选项
    AMapGeocodeSearchRequest *searchRequest = [[AMapGeocodeSearchRequest alloc] init];
    searchRequest.address = address;
    //发起正向地理编码
    [self.searchAPI AMapGeocodeSearch: searchRequest];
}
- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response
{
    if (response.geocodes.count == 0) {
        return;
    }
    NSArray *locationInfo = response.geocodes; // 用户位置信息
    AMapGeocode *geocode = locationInfo.firstObject;
    AMapGeoPoint *geoPoint = geocode.location;
    CLLocationCoordinate2D Coordinate2D = CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude); // 根据地址获取的经纬度
    [self.mapView setCenterCoordinate:Coordinate2D animated:YES];// 在地图上设置出该位置
    NSString *geocodeString = [NSString stringWithFormat:@"经纬度:%f,%f", geoPoint.latitude, geoPoint.longitude];
}*/

#pragma mark -- 逆向地理编码 (根据经纬度获取地名)
// latitude longtitud 传入经纬度
- (void)getNameByLatitude:(CLLocationDegrees)latitude andLongTitude:(CLLocationDegrees)longtitud 
{
    self.searchAPI = [[AMapSearchAPIalloc]init];
    self.searchAPI.delegate =self;
    AMapReGeocodeSearchRequest *regeoRequest = [[AMapReGeocodeSearchRequestalloc]init];
    regeoRequest.location = [AMapGeoPointlocationWithLatitude:latitudelongitude:longtitud];
    regeoRequest.radius =2000;
    regeoRequest.requireExtension =YES;
    [self.searchAPIAMapReGoecodeSearch: regeoRequest]; 
// 发起检索
}

- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse
*)response
{
    if (![DDUtilsisNullOrNil:response.regeocode])
{
        AMapReGeocode *regeocode = response.regeocode;
        CLLocationDegrees latitude = request.location.latitude;
        CLLocationDegrees longitude = request.location.longitude;
        NSString *address = regeocode.formattedAddress; // 获得检索位置 
    } 
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: