Hey everyone, I’m working on an iOS app and I need some help. I want to find out the driving distance between two points using the Google Maps API. But here’s the catch - I don’t want to use a UIWebView.
Here’s what I’m trying to do:
- I have two points with latitude and longitude
- I need to calculate the driving distance between them
- I want to do this on the server-side, not in the app
I tried loading an HTML page that uses JavaScript to get the distance, but I’m just getting the raw JavaScript code instead of the result. Is there a way to process this JavaScript using Objective-C or PHP?
My end goal is to send a request with the coordinates and get back JSON data with the distances. Any ideas on how to make this work? Thanks in advance for your help!
hey mate, have u tried the google maps distance matrix api? it’s pretty sweet for this kinda thing. u can hit it from ur server with the coordinates and get back json with the distance. no need for uiwebview hassle. just remember to watch ur api usage, google can get pricey if ur not careful. hope this helps!
Hey there! I’ve actually tackled this issue before in one of my projects. Instead of using UIWebView, I found that the Google Maps Distance Matrix API is a solid solution for calculating driving distances server-side.
I set up a simple PHP script on my server to handle the API requests. It takes the coordinates, sends a request to the Google API, and returns the distance data as JSON. In my iOS app, I just make a network call to my server endpoint with the coordinates.
One tip: cache frequently requested routes to save on API calls. Also, be mindful of usage limits – Google can get pricey if you’re doing a ton of requests.
If you’re looking for a free alternative, check out OpenStreetMap’s routing services. They’re not as polished as Google, but they get the job done for most cases.
Hope this helps! Let me know if you need any more details on the implementation.
For calculating driving distances without UIWebView, I’d recommend using the Google Maps Distance Matrix API. It’s a server-side solution that’s quite straightforward to implement.
You’ll need to make HTTP requests to the API with your origin and destination coordinates. The API returns JSON data with distance and time info. You can process this server-side using PHP or another language, then send the results back to your iOS app.
Remember to use an API key and be mindful of usage limits. Also, consider caching frequent routes to reduce API calls. This approach is more efficient and secure than processing JavaScript in a UIWebView.
If you’re concerned about API costs, OpenStreetMap offers a free alternative, though it might be less accurate for some regions.