Google Directions API limited versus Google Directions Javascript.API - google-maps

If I make a request via javascript, I get a JSON object returned that has Routes, Legs, Steps ,and Path data, the latter being a set of Lat,Lng co-ordinates along the step.
https://maps.googleapis.com/maps/api/js?...query for the javascript and then using the directionsService function
If I make a request server-side, with exactly the same request, I only get Routes, Legs and Steps data returned, no Path data.
https://maps.googleapis.com/maps/api/json?...query
Has anyone else experienced this? are there any workarounds? Uisng the other URL in each application just returns a 404.

You can extract path data from the polyline property of the step:
polyline contains a single points object that holds an encoded polyline representation of the step. This polyline is an approximate (smoothed) path of the step.
https://developers.google.com/maps/documentation/directions/intro#DirectionsResponseElements
Encoded polyline algorithm is described here:
https://developers.google.com/maps/documentation/utilities/polylinealgorithm
Google Maps JavaScript API has a static method in geometry library to decode the encoded polyline:
https://developers.google.com/maps/documentation/javascript/reference#encoding
For Android apps you can use Google Maps Android API utility library that contains polyline decoding and encoding functions:
https://github.com/googlemaps/android-maps-utils
Google Maps iOS SDK also has static method to obtain a path from encoded polyline:
https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_path
Hope it helps!

Related

How to get box using routeBoxer using Google Direction apis in php?

I am trying to get overview_path in google direction api, but it not appearing in the response.
When i am using js sdk , I am getting the overview_path array in routes array but when I tried calling the direction api in postman, overview_path array is missing in the routes array.
Here is the url of postman.
https://maps.googleapis.com/maps/api/directions/json?origin=Disneyland&destination=Universal+Studios+Hollywood4&key=please_add_your_key&alternatives=true&units=metric&mode=driving
I am trying to get boxes for my path using routeBoxer.
There is overview_polyline which is encoded version of the overview_path, you need to decode it and you will get lat, lng of it.
http://unitstep.net/blog/2008/08/02/decoding-google-maps-encoded-polylines-using-php/

google maps javascript is fetching the route but not the json api

I have stumbled upon this: when I use directionsDisplay.getDirections() API to fetch and display the results, it works, but when I do it via json:
https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJR0FT51wiDogRNuVKiLn9ZLA&destination=place_id:ChIJMWaiY0YpTIYRRdGvCMg7m0g&key=MY_KEY&waypoints=via:place_id:ChIJaWS37r88DIgRu-ak1l7eXAQ
I get "status" : "ZERO_RESULTS"
I am wondering why this might be happening? Any ideas?
Remove the "via:" keyword from the waypoints to get the response.
https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJR0FT51wiDogRNuVKiLn9ZLA&destination=place_id:ChIJMWaiY0YpTIYRRdGvCMg7m0g&key=MY_KEY&waypoints=place_id:ChIJaWS37r88DIgRu-ak1l7eXAQ
From the documentation:
The via: prefix is most effective when creating routes in response to the user dragging the waypoints on the map. Doing so allows the user to see how the final route may look in real-time and helps ensure that waypoints are placed in locations that are accessible to the Google Maps Directions API.
Caution: Using the via: prefix to avoid stopovers results in directions that are very strict in their interpretation of the waypoint. This may result in severe detours on the route or ZERO_RESULTS in the response status code if the Google Maps Directions API is unable to create directions through that point.

Can we use overview_polyline into waypoints of particular route duration

I am using google direction service API to get route and it's distance with route drag option.
For example if i create a route between A & B. then i have dragged the original google given path to my own.
then i need to save my custom route (dragged route) and show the future reference.
In that case can i use overview_polyline (direction response json node value) into waypoints to show exact my custom route.
Please help me
Sure, you can store the overview_polyline and later use it to draw a polyline which will restore your customized route.
To do this you will need a geometry library and call a google.maps.geometry.encoding.decodePath() method to get the array of your points.
After that you can use this array to construct a Polyline object.
Please have a look at this sample code:
http://jsbin.com/kijaze/1/edit?html,output

Display Google Map API route on map

I am new to google Map Api V3, and i am planning to find the best route among some waypoint.
I found that the direction API could solve my problem (http://maps.googleapis.com/maps/api/directions/json?...)
I got the Json output, but is there any way to display the route on Google map directly?
Or i should parse the Json, get the legs information, and plot it again??
Thanks a lot

How to get dynamically latitude and longitude on google maps?

I have country and address. How can I retrieve latitude and longitude from Google Maps V3?
I will use this to load the map.
EDIT
This is my actual code, but seems that Google API return this error : W[B].bindTo=function(a,b,c,d){var c=c|...R[p](this,wf,a);this.Pb&&this.Pb(a)};
SOLUTION
remove center: location,
You can retreive this with Geocoding Requests.
You can see my last project that I used this here. See function AddMarker in gmaps3.js for a working real world example. Basically I fetch addresses from database (using AJAX) and then convert them to lat/lon to make markers on the map.
You can use their ReST-API.
http://maps.google.com/maps/api/geocode/json?address=Berlin+Germany&sensor=false
The documentation is in The Google Geocoding API. You will have to do a http request e.g. $.get in jQuery to perform the query and then parse the JSON. Other output formats include XML. There's a JavaScript geocoder on their site as well.
You need to access geocoding.
http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
http://code.google.com/apis/maps/documentation/geocoding/index.html