Domanda

I am trying to fetch address(only nearest street, landmark or feature and closest city, village, or town). I tried 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 but in google api its returning so many json objects and its quite confusing and in nominatim's api sometimes it doesn't return any result or miss some fields in short its not returning precise result. Can anybody suggest me any other api or any reference for that?

È stato utile?

Soluzione

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

Altri suggerimenti

You can try the method:

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

You will get answer in google map documentation so go thought it

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

I built a Swift 3 wrapper for OpenStreetMap's Nominatim. Check it out here: https://github.com/caloon/NominatimSwift

NominatimSwift uses the free Nominatim API for geocoding of OpenStreetMap data. You can also search for landmarks. It requires network connectivity.

Geocoding addresses and landmarks:

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)!)
})

Reverse geocoding:

Nominatim.getLocation(fromLatitude: "55.6867243", longitude: "12.5700724", completion: {(error, location) -> Void in
  print("City for geolocation 55.6867243/12.5700724:")
  print(location?.city)
})
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top