如何在IOS中查找经纬度的地址?

时间:2014-04-03 07:21:22

标签: ios latitude-longitude street-address

我正在尝试获取地址(只有最近的街道,地标或特色以及最近的城市,村庄或城镇)。我试过了         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     但是在google api中它返回了这么多json对象并且它非常令人困惑,并且在名词的api中,有时候它不会返回任何结果或者错过某些字段而不会返回精确的结果。任何人都可以建议我任何其他api或任何参考?

4 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

您可以尝试以下方法:

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

答案 2 :(得分:0)

您将在谷歌地图文档中得到答案,所以去认为

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

答案 3 :(得分:0)

我为OpenStreetMap的Nominatim构建了一个Swift 3包装器。请在此处查看:https://github.com/caloon/NominatimSwift

NominatimSwift使用免费的Nominatim 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)
})