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.
Related
I currently have an application which takes a a start and end point from a user and sends a request to the google maps directions API, for example: https://maps.googleapis.com/maps/api/directions/xml?key=my_key8&origin=M460PU&destination=NN36NW&sensor=false&mode=driving&units=imperial&departure_time=1501752779
We then display the estimated journey time for a given route. The user has asked if it's possible for us to include a link directly to Google maps so that they can see the route on the maps and make sure it looks ok.
I've seen previous questions such as this one: Link to Google Maps but that seems to be a solution for a simple Google Maps search, where as in my case I want to see a route from the directions API.
I'm trying to figure out if I there's a way I can take the data from the Directions API response and plug that in to a http://maps.google.com/maps URL that the user can click on. Has anyone ever had any success doing this?
As mentioned #geocodezip you should use Google Maps JavaScript API or Google Static Maps API in order to show exactly the same route as the output of Directions API.
There is also an option to open Google Maps web site or native app using the Google Maps URLs. You can have a look at the documentation to figure out how to create the URL:
https://developers.google.com/maps/documentation/urls/guide#directions-action
The only issue is that the Google Maps URLs doesn't provide any parameter for departure time, so you will always get routes for "Leave now" that might have discrepancies comparing to a web service that was requested for a different departure time.
Based on your question I think the Google Maps URL might be
https://www.google.com/maps/dir/?api=1&origin=M460PU&destination=NN36NW&travelmode=driving
I want to send an address via Google API and get a response if this is a valid or wrong address. If it's a wrong address the response will include the reason (e.g. wrong zip code, wrong state etc.)
Is it possible?
Thanks
Google Maps APIs are not intended for address validation. They do, however, provide a variety of other services including geolocation, directions, distance calculation, and much more. For a list of APIs as well as what they can do for you please check out the API Picker here:
https://developers.google.com/maps/documentation/api-picker
I hope this helps!
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.
Is there a way to check whether an address you pass into Google Maps to get direction with the URL scheme exists?
You could try making a geocode request, and then see if you get a response of OK (the address could be converted into a location, so it exists), or ZERO_RESULTS (the address doesn't exist). Presumably when you start the Google Maps app with a URL scheme, Google uses the same geocoder internally to look up the address.
https://developers.google.com/maps/documentation/geocoding/
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.