地图地理编码(逆向)

1.百度地图定位
  • 需要调用代理方法设置 - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation , 从代理方法里获取当前最新的location.
  • 创建BMKGeoCodeSearch进行反地理编码,记得挂代理
    self.getCodeSearch = [[BMKGeoCodeSearch alloc] init];
    self.getCodeSearch.delegate = self;
    //1.创建反向地理编码选项对象
    BMKReverseGeoCodeOption *reverseOption=[[BMKReverseGeoCodeOption alloc]init];
    //2.给反向地理编码选项对象的坐标点赋值
    reverseOption.reverseGeoPoint=userLocation.location.coordinate;
    //3.执行反地理编码
    [self.getCodeSearch reverseGeoCode:reverseOption];
  • 执行代理方法,获取反地理编码
-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
    BMKAddressComponent *component=[[BMKAddressComponent alloc]init];
    component=result.addressDetail;
    [self.locationBtn setTitle:[NSString stringWithFormat:@"%@%@", component.streetName?:@"", component.streetNumber?:@""] forState:0];
}
  • 补充说明
    使用对应的地图获取出来的经纬度,只能使用对应的正向/反向地理编码进行解析, 以上是百度地图解析地理编码的方法
2.系统自带方法

1.设置参数

- (void)reveLocation
{
//定位初始化
    CLLocationManager * locationManager=[[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = 10;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager requestWhenInUseAuthorization];
    [locationManager startUpdatingLocation];
}

2.实现回调,执行代理方法

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    //此处locations存储了持续更新的位置坐标值,取最后一个值为最新位置,如果不想让其持续更新位置,则在此方法中获取到一个值之后让locationManager stopUpdatingLocation
    CLLocation *currentLocation = [locations lastObject];
    // 获取当前所在的城市名
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    //根据经纬度反向地理编译出地址信息
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *array, NSError *error)
     {
         if (!error)
         {
             CLPlacemark *place = array.lastObject;
             _locationName = place.name;
         }
         else
         {
         }
     }];
}
3.高德地图

1.设置参数,进行逆地理

- (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];
  
}

2.实现回调,获取查询结果:

-  (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request  response:(AMapReGeocodeSearchResponse *)response
  
{
  
  NSString *result = [NSString stringWithFormat:@"ReGeocode:  %@", response.regeocode];
  
  NSLog(@"ReGeo: %@",  result);
  
}

你可能感兴趣的:(地图地理编码(逆向))