views:

1672

answers:

2

I want to access some data from Google maps. the only way possible is using JS for that. I'm not trying to access it through a webview.

usercase:

  • I have point 1 (lat,lng) and point 2 (lat,lng). I want to use Google maps api to determine what the driving distance is between those 2.

So in other words I want to use the Google maps api at server-side.

Now when I try to load the data for that html page (that uses document.write() for parsing the distance) I get the Javascript instead of the Javascript being processed.

Can I in any way let the Javascript process through Objective-C ? PHP?

My ultimate goal is to send a request with post vars with the different points and get my data back in JSON for every distance between 2 points

+1  A: 

You need to have some container on your server to execute the Javascript in. Just loading the Javascript from a HTTP request does not execute it.

Have you looked at CloudMade's routing APIs. They sound like a better solution for your requirements

Roger Nolan
using cloudmade's routing api's is definitely a wise choice :)do you know how can i setup a container for executing javascript ?
Andy Jacobs
I'm not a server guy but if I was, I'd start here: http://en.wikipedia.org/wiki/Server-side_JavaScript
Roger Nolan
A: 

You need UIWebView to run the JavaScript. Here's way I prefer:

  1. Subclass a UIWebView, and add it to the subview of UIView (so you can control your UI gesture on UIView at the same time)
  2. Ask UIWebView to load your PHP webpage that handles the JavaScript you want to use.
  3. You use stringByEvaluatingJavaScriptFromString: to execute the script in your App.
  4. Finally, sever side PHP webpage can respond your script execution.

There's small sample/project in Google Code does the trick: iphone-google-maps-component, the guy uses a UIWebView to load the custom version Google Maps, and provides a set of Objective-C methods to control the map.

digdog