Google Maps api access possibilities for iphone? (processing javascript without UIWebView)
-
03-07-2019 - |
Question
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
Solution
You need UIWebView to run the JavaScript. Here's way I prefer:
- Subclass a UIWebView, and add it to the subview of UIView (so you can control your UI gesture on UIView at the same time)
- Ask UIWebView to load your PHP webpage that handles the JavaScript you want to use.
- You use stringByEvaluatingJavaScriptFromString: to execute the script in your App.
- 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.
OTHER TIPS
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