Search code examples
iphonegeolocationcllocation

How to find the long and lat of a city on the iphone?


I am trying to find the long and lat of a city on the iphone. Say the user is searching for London, I would call some function that would retrieve the long and lat of London. I have looked on the web and found you can use a Google API but there must be an Apple function somewhere to handle this?

I have come accross the MKReverseGeocoder which takes the long and lat and tells you what city you are near. e.g.

// reverse geocode the user location

geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];

If it can reverse the process there must be some form of MKGeocoder class?


Solution

  • but there must be an Apple function somewhere to handle this

    Why must there be? Because there isn't.

    There are a number of web services you can use (e.g. Google) or you could download a place name database such as http://www.geonames.org/ and import it into your app. It's probably best to import it into an SQL database which you can then search from your app.