代码之家  ›  专栏  ›  技术社区  ›  rahul

如何在IOS中从纬度和经度找到地址?

  •  1
  • rahul  · 技术社区  · 11 年前

    我正在尝试获取地址(只有最近的街道、地标或特色以及最近的城市、村庄或城镇)。我试过了 http://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&sensor=true http://nominatim.openstreetmap.org/reverse?format=json&lat=44.4647452&lon=7.3553838&zoom=18&addressdetails=1 但在googleapi中,它返回了太多的json对象,而且非常令人困惑,在nomitim的api中,有时它不返回任何结果,或者忽略了某些字段,简而言之,它不返回精确的结果。有人能给我推荐其他api或参考吗?

    4 回复  |  直到 11 年前
        1
  •  1
  •   Thukaram    11 年前
    -(void)getAddressFromCurruntLocation:(CLLocation *)location{
    
        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
       [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
       {
         if(placemarks && placemarks.count > 0)
         {
             CLPlacemark *placemark= [placemarks objectAtIndex:0];
             //address is NSString variable that declare in .h file.
             address = [[NSString stringWithFormat:@"%@ , %@ , %@",[placemark thoroughfare],[placemark locality],[placemark administrativeArea]] retain];
             NSLog(@"New Address Is:%@",address);
         }
     }];
    }
    
        2
  •  0
  •   Lolloz89    11 年前

    您可以尝试以下方法:

    CLGeocoder *geocoder = [CLGeocoder alloc]init];     
    [geocoder reverseGeocodeLocation:location completionHandler:
                ^(NSArray* placemarks, NSError* error){}];
    

    https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/UsingGeocoders/UsingGeocoders.html#//apple_ref/doc/uid/TP40009497-CH4-SW1

        3
  •  0
  •   Sukeshj    11 年前

    你会在谷歌地图文档中得到答案,所以去想一想吧

    https://developers.google.com/maps/documentation/geocoding/?csw=1#JSON

        4
  •  0
  •   Josef Moser    8 年前

    我为OpenStreetMap的Nomatim构建了一个Swift 3包装器。在这里查看: https://github.com/caloon/NominatimSwift

    NomatimSwift使用免费的Nomatim API对OpenStreetMap数据进行地理编码。您还可以搜索地标。它需要网络连接。

    地理编码地址和地标:

    Nominatim.getLocation(fromAddress: "The Royal Palace of Stockholm", completion: {(error, location) -> Void in
      print("Geolocation of the Royal Palace of Stockholm:")
      print("lat = " + (location?.latitude)! + "   lon = " + (location?.longitude)!)
    })
    

    反向地理编码:

    Nominatim.getLocation(fromLatitude: "55.6867243", longitude: "12.5700724", completion: {(error, location) -> Void in
      print("City for geolocation 55.6867243/12.5700724:")
      print(location?.city)
    })