地图地理编码(逆向)

2017-09-05  本文已影响79人  只因为趁年轻
1.百度地图定位
    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);
  
}
上一篇下一篇

猜你喜欢

热点阅读