Is there a way to use Google Maps API on iOS without UIWebView?

Hey everyone! I’m working on an iOS app and I need to get some info from Google Maps. The problem is I can’t use a UIWebView. Here’s what I’m trying to do:

I’ve got two points with latitude and longitude. I want to find out how far it is to drive between them. I know I need to use JavaScript for this, but I’m not sure how to do it without a web view.

Is there a way to run the Google Maps API stuff on the server side? Or maybe process the JavaScript using Objective-C or PHP?

What I really want is to send a request with the coordinates and get back the distances in JSON format. Any ideas on how to make this work?

Thanks in advance for your help!

I’ve tackled this issue before in one of my projects. Instead of relying on UIWebView, I’d recommend using Google’s Directions API directly. It’s a RESTful service that you can call from your iOS app using standard HTTP requests.

Here’s the gist: You send a GET request to the API with your start and end coordinates, and it returns JSON with detailed route info, including distance and duration. You’ll need to parse this JSON on the client side, but it’s straightforward with iOS’s built-in JSONDecoder.

Keep in mind you’ll need a valid API key, and there are usage limits and potential costs to consider. But overall, it’s a clean solution that avoids the need for JavaScript or web views entirely.

If you’re looking for an even more native approach, Apple’s MapKit framework has improved significantly. It now offers routing capabilities that might suit your needs without relying on Google’s services at all.

Have you considered using the Google Maps SDK for iOS? It’s a native solution that doesn’t require UIWebView. One can easily calculate driving distances between two points using the GMSDirections class. For example, you can install the SDK via CocoaPods or manually, then initialize it with your API key. Next, create instances of GMSDirectionsService and GMSDirectionsRequest, set the origin and destination coordinates in the request, and finally call calculateDirections(request:) to retrieve the route. The result includes distance, duration, and other useful data. This native approach eliminates the need for JavaScript and offers benefits like offline caching and improved performance. Remember to review Google’s pricing and usage limits before implementation.

hey mikechen, have u tried using the google maps sdk for ios? It’s prety solid and lets u do distance calcs without webviews. Just grab the SDK, init it w/ ur API key, and use the GMSGeometryDistance() function. Shud give u wat u need without messin with javascript. good luck!