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

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.

Related

Google Map API: Display of alternative bus routes possible?

So far I am only able to show a only single bus route when using Google Maps API v3. However on google websites, one active route and other 2-3 grayed out ones are shown.
Is there an option in the API v3 to enable alternative bus routes or do I have to custom code that feature?
How do you select directions for specific time and date in future like on google maps?
you'll need to set the provideRouteAlternatives-option of the DirectionsRequest to true, then you may(when available) get alternative routes.
To draw the multiple routes you must create separate DirectionsRenderer-instances for each route and set the index of the desired route as routeIndex-property of the DirectionsRenderer
the time(departure/arrival) may be specified via the transitOptions of the DirectionsRequest

Verify an Address with Google Maps Static API

I use google maps static api to show maps on my website and use the following url:
http://maps.googleapis.com/maps/api/staticmap?center=usa&size=800x300&maptype=roadmap&sensor=false&markers=color:blue|label:S|usa
However, if enter a non-existing address, google will return a picture like this:
http://maps.googleapis.com/maps/api/staticmap?center=notexistingaddress&size=800x300&maptype=roadmap&sensor=false&markers=color:blue|label:S|notexistingaddress
I would like to know, how can I determine, if an address exists or not, using google maps static api. I cannot use javascript, because this code is executed on server.
After reading the docs, I think that the Google Maps Static API has nothing (exept the way I suggest like verify the return of the picture manually or only the keyword notexistingaddress) to verify if an address exists or not.
The best way to do validation is I think the Google Geocoding API, where you can outpout a Json / XML of a given address. The status code of ZERO_RESULTS which indicates that the geocode was successful but returned no results may interest you.

ALL google maps Directions web service API requests with mode=transit return INVALID_REQUEST

Here are a few URLs that return results with walking or driving but not with transit (i.e., change mode to walking or driving and you will see results)
http://maps.googleapis.com/maps/api/directions/json?origin=EC3N4AB&destination=EC4M8AD&sensor=false&mode=transit
http://maps.googleapis.com/maps/api/directions/json?origin=Toledo&destination=Madrid&region=es&sensor=false&mode=transit
I cant get a single response with mode=transit. Notice that the second URL is straight from API documentation
Anyone else noticing the same thing?
Sorry. Its not the global thing
E.g, this doesnt work:
http://maps.googleapis.com/maps/api/directions/json?origin=san+francisco&destination=seattle&sensor=false&mode=transit
But, this does again:
http://maps.googleapis.com/maps/api/directions/json?origin=san+francisco&destination=seattle&sensor=false&mode=transit&departure_time=1343376768
Its not the global issue. Its that google made departure_time or arrival_time as a mandatory field. This is a recent change to their API.
Thanks for all your help
Transit directions don't work globally. For example, this request works:
http://maps.googleapis.com/maps/api/directions/json?origin=san+francisco&destination=seattle&sensor=false
On the other hand if you go to maps.google.com and attempt to get transit directions via the UI from Toledo to Madrid, it notes the request is outside the coverage area. The way the API returns this information is via the INVALID_REQUEST status.

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

Google maps geocoding API inconsistent

I have a server application that calls the google maps geocoding API at http://maps.googleapis.com/maps/api/geocode/json
I experience that when the server application invokes such an URL, the response is sometimes ZERO_RESULTS.
If I take the exact same URL and paste in a browser, I get a valid result back.
Any ideas to what differences can cause this? HTTP headers? Something else?
In the link you provided it is missing the address, components, latlng or place_id parameters, besides the Google Map API KEY.
You need at least one of the parameters and the Key to get a proper response.
e.g.
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ1xwGTLE1K4gRmzFDd_1HzPc&key=xxx
Just add your KEY and it should work.