views:

30128

answers:

12

Update: iPhone SDk 3.0 now addresses the question here, however the NDA prevents any in depth discussion. Log in to the iPhone Dev Center if you need more info.

Ok, I have to admit I'm a little lost here.

I am fairly comfortable with Cocoa, but am having trouble picking up the bit of javascript needed to solve this problem.

I am trying to send a request to Google for a reverse geo code.

I have looked over the Google documentation I have viewed here: http://code.google.com/apis/maps/documentation/index.html http://code.google.com/apis/maps/documentation/geocoding/

Even after a rough reading, I am missing a basic concept:

How do I talk to google? In some examples, they show a url being sent to google (which seems easy enough), but in others they show javascript. It seems for reverse geocoding, the request might be be harder than sending the url with some parameters (but I hope I am wrong).

Can someone point me to the correct way to make a request? (In objective-C, so I can wrap my head around it)

A: 

Also try to take a look at google maps component.

Alfons
+6  A: 

UPDATE - iPhone 0.3 includes MapKit, which will hopefully be significantly faster than using the JS API. The blurb says that it will include reverse geocoding.

You can't make a request directly in objective-C, at least not within the terms of the Google API. The Google API is written in Javascript. You could use an objective-c to JS bridge, as the Google Maps Component does, but that doesn't really solve the issue - you're still making JS calls!

Unfortunately, that means you a) need to use a webview b) need to use the JS API which is slow... compare with the Google Maps application which uses a completely different OTA protocol (try packet sniffing it).

The Google Maps Component is, however, a useful tutorial in how to make simple calls to the API.

Airsource Ltd
Thanks, it seemed like it was something like tedious that. Confirms my fears, as I only want to reverse geocode an address. Seems like that would be trivial.
Corey Floyd
+3  A: 

The easiest way to get a Google map using Cocoa is to use the "Static Maps API". In practice, you need to prepare an NSURL that you use to contact Google. You get back your map as NSData, that you transform to an NSImage. Note that you can do both geocoding and reverse geocoding. You can also embed markers on the map. However, you loose the full controls you have access to if you use their JavaScript API.

Take a look at their reference guide here:

http://code.google.com/apis/maps/documentation/staticmaps/

unforgiven
+1  A: 

For your information: The reverse geocoding API from Google for requests by XML isn't public, so it's illegal to use. The only legal way is going through their JavaScript-API, which as you found out is harder to do in Cocoa than to simply send an HTTP request.

Alternatives: Reverse geocoding with simple XML/JSON requests is also available from Geonames or Yahoo.

christian studer
A: 

Actually, I did not meant reverse geocoding as "translating a point into a human-readable address", but rather visualizing a point using a Google Map (that can also, depending on the accuracy level, show a human-readable address). This is the basic functionality that was required.

In practice, I just wanted to suggest the static maps API as a clean and fast way to:

1) given the coordinates obtained from the iPhone GPS sensor, retrieve a Google Map showing the point

2) given an address, transform it in the corresponding geographical coordinates and then use the coords to retrieve a Google Map showing the address given

Both are possible using simple NSURLs involving the staticmap and geo services

http://maps.google.com/staticmap? http://maps.google.com/maps/geo?

passing of course the needed parameters to provide a suitable query string.

Kind regards

unforgiven
+1  A: 

Now that apple have release the MapKit API for OS 3.0, I think your question has been answered. Having looked at the API docs, I can see a heck of a lot of potential! I still would like to see reverse geocoding webservice from Google, but Yahoo will do in the meantime.

A: 

The big issue of course, is that the license agreement of both google and yahoo state you can't use these API's in "commercial applications". would hate to pub an app on the app store only to have it taken down and sued by yahoo or google. In reading the iPhone 3.0 map api and associated license this isn't mentioned but if you want an app to run on phones not upgraded....

Is there an answer for this that won't get one in trouble?

A: 

http://blog.cloudmade.com/2009/06/12/how-to-get-forward-geocoding-in-iphone-mapkit/

CloudMade seems to be an open-source map/location provider - the above blog post lists details on how to get forward geocoding.

John
A: 

Has anyone able to get the CloudMade apis working properly. I seeing a ton of errors trying to get the apis to run.

Zap

A: 

deCarta has a pretty good iPhone API. http://www.decarta.com/developer/

Ryan
A: 

If you're looking for forward geocoding check out my forward geocoding API for Google maps: http://blog.sallarp.com/ipad-iphone-forward-geocoding-api-google/

Merrimack