OK, here's what I want to implement and I need your ideas :
- Input a geo location by name/address/etc (e.g.
London, Oxford Street 20
)
- Get the point's longitude/latitude
My Questions :
- How would you go about that?
- Is using Google Maps API (that's what I first thought of) my only solution?
It'd be better if the service used CAN be freely integrated in a commercial app - so any idea is welcome... :-)
There is a built in API for that.
For iOS 5 and newer you can use CLGeocoder and for older version you will need to use some extern libraries.
Just call
- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler
where you want to get the location. It runs async and in the completionHandler
you will get an array of all possible placemarks for your address where the first one is the most accurate. As apple says:
For most geocoding requests, this array should contain only one
entry. However, forward-geocoding requests may return multiple
placemark objects in situations where the specified address could not
be resolved to a single location.
Off topic:
Am I the only one whos first thoughts about Oxford
was "What does he mean with this weird Hex value?"
What you are trying to do is basically geocoding. Major map providers like Google, Bing and Yahoo (and many more) all offer some form of Geocoding API for you to take advantage of. Check out the following quick links:
- Google Maps Geocoding API
- Bing Locations API
- Yahoo! Maps Web Services (Geocoding API)
Edit: (just saw the objective-c tag)
Note that these are non-native solutions. However, the provided APIs are typically REST-based (with output as xml/json), it shouldn't be hard for you to consume these services to grab the gecoded lat-long that you want from within your app.