我正在尝试获取地址(只有最近的街道,地标或特色以及最近的城市,村庄或城镇)。我试过了 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或任何参考?
答案 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){}];
答案 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)
})