views:

44

answers:

3

Hi, 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?

+1  A: 

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.

Ole Begemann
A place name database would be more feasible than Google since it would work offline. There must be an Apple way, If I goto the standard Map APP, I can search for London and I get nice pin drop on the map in the centre of london? If they can do it there we must be able to use the same method.
woot586
Apple can do a lot of things third-party devs can't do. I assume Apple uses Google's geocoding service. It makes sense since the Maps app doesn't work offline anyway.
Ole Begemann
Thanks Ole, I have had a play with Geonames and I am pleased with the speed and simplicity you can get the results just hit the URL http://www.geonames.org/search.html?q=london and you get the latitude and longitude in the first result. Also with the database you can download (http://download.geonames.org/export/dump/) and have a offline version.
woot586
A: 

See OpenStreetMap. It gives you more flexibility in accessing its data. You could pre-populate a CoreData store with the informations you need.
There are some api-clients, i.e. route-me or cloudmade.

vikingosegundo
A: 

First, give up that there "must be" an Apple way. There really isn't. If you don't believe me and my nearly 2k of experience points, listen to Ole and his 13k.

There are three services I've seen.

I tried Google's geocoding API. It's decent, but a bit complicated, and they throttle your queries pretty harshly.

Then I tried MapQuest's, which I found to be surprisingly excellent. I have two apps bound for the app store in the next month or so that use MapQuest's API.

Then I found Geonames, which I'm very impressed by but haven't had the opportunity to use yet. Note that Geonames DOES allow you to download their data, so if you really need network-free service, this might be a solution.

Apart from that, you're going to be calling something off the device. Which, by the way, you are when you use MKReverseGeocoder--that's just a wrapper around Google's reverse geocoding service.

Dan Ray