PruitIgoe
PruitIgoe

Reputation: 6384

Google Maps Directions API

Does the JSON returned on a Directions API query provide the lat/long of the waypoints sent?

I have a situation where I am adding a map feature to a app used by our sales team. For each sales rep I get their customer list out of SAP, the geo data for each customer is provided by a 3rd party service. In the app I have the customers stored in Core Data as a Customer entity, with properties for lat/long. I use those to make the customer marker (pin) on the map.

The app lets the sales team map out their day. On occasion, the route drawn (from addresses sent to the Directions API) will not touch all of the customer markers (see image below)enter image description here

From comparing to Google Maps I am getting a match for the markers, first image is my map, second is Google's web site:

enter image description here

enter image description here

And the address I used to get the pin on the Google Map web site is the same address I am sending to the Google Directions API.

Additionally, if you look at the zoom in of my map, the polylines returned are not even hitting any actual roads. The request is not being optimized, just sending a origin, destination, series of waypoints and getting the results and displaying. Is this on my end or Googles and if it is my end, how can I resolve it?

Edit: If I change some of the customers and resubmit the Directions request Google seems to be able to resolve the directions. I think this is a Google issue.

enter image description here

Thanks

Upvotes: 0

Views: 656

Answers (1)

Sanman
Sanman

Reputation: 1158

You get waypoints indirectly in the legs array returned by google directions api.For ex. if you add only one waypoint you'll get two objects in legs array with first object having waypoint as its end_location with latitude and longitude (as you asked) and waypoint as start_location for second object. "waypoint_order" provides order in in which your waypoints are added to the route.I have used waypoints=optimize:true to get optimized waypoint usage.just check out response json and you'll get it.Hope it helps... :)

Upvotes: 1

Related Questions