地圖地理編碼(逆向)

1.百度地圖定位
  • 需要調(diào)用代理方法設(shè)置 - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation , 從代理方法里獲取當(dāng)前最新的location.
  • 創(chuàng)建BMKGeoCodeSearch進(jìn)行反地理編碼,記得掛代理<BMKGeoCodeSearchDelegate>
    self.getCodeSearch = [[BMKGeoCodeSearch alloc] init];
    self.getCodeSearch.delegate = self;
    //1.創(chuàng)建反向地理編碼選項對象
    BMKReverseGeoCodeOption *reverseOption=[[BMKReverseGeoCodeOption alloc]init];
    //2.給反向地理編碼選項對象的坐標(biāo)點(diǎn)賦值
    reverseOption.reverseGeoPoint=userLocation.location.coordinate;
    //3.執(zhí)行反地理編碼
    [self.getCodeSearch reverseGeoCode:reverseOption];
  • 執(zhí)行代理方法,獲取反地理編碼
-(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];
}
  • 補(bǔ)充說明
    使用對應(yīng)的地圖獲取出來的經(jīng)緯度,只能使用對應(yīng)的正向/反向地理編碼進(jìn)行解析, 以上是百度地圖解析地理編碼的方法
2.系統(tǒng)自帶方法

1.設(shè)置參數(shù)

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

2.實現(xiàn)回調(diào),執(zhí)行代理方法

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    //此處locations存儲了持續(xù)更新的位置坐標(biāo)值,取最后一個值為最新位置,如果不想讓其持續(xù)更新位置,則在此方法中獲取到一個值之后讓locationManager stopUpdatingLocation
    CLLocation *currentLocation = [locations lastObject];
    // 獲取當(dāng)前所在的城市名
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    //根據(jù)經(jīng)緯度反向地理編譯出地址信息
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *array, NSError *error)
     {
         if (!error)
         {
             CLPlacemark *place = array.lastObject;
             _locationName = place.name;
         }
         else
         {
         }
     }];
}
3.高德地圖

1.設(shè)置參數(shù),進(jìn)行逆地理

- (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.實現(xiàn)回調(diào),獲取查詢結(jié)果:

-  (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request  response:(AMapReGeocodeSearchResponse *)response
  
{
  
  NSString *result = [NSString stringWithFormat:@"ReGeocode:  %@", response.regeocode];
  
  NSLog(@"ReGeo: %@",  result);
  
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容