google maps directions zero_result [duplicate] - google-maps

We are calling the google directions api to calculate round trip values. In general it works perfectly. I have however come across a use case where it fails to come up with any route. However when we use the js google.maps.DirectionsService version with the same origin, destination, waypoints, and travelMode it works.
The failing call is:
https://maps.googleapis.com/maps/api/directions/json?origin=-33.92873,18.458879&destination=-33.92873,18.458879&waypoints=via:-33.9403,18.666731&mode=driving&key=
The response is
{
"geocoded_waypoints" : [ {}, {}, {} ],
"routes" : [],
"status" : "ZERO_RESULTS"
}

When you use via: prefix (no stopover), it adds some additional restrictions. Particularly the U-turn maneuver is not allowed, the route must go straight forward through waypoint. If this is impossible the Directions service will return ZERO_RESULTS.
To check this hypothesis I created exactly the same request, but with stopover (without via: prefix). You can see the result in the Directions calculator:
https://directionsdebug.firebaseapp.com/?origin=-33.92873%2C18.458879&destination=-33.92873%2C18.458879&waypoints=-33.9403%2C18.666731
Indeed, you should do the U-Turn in -33.9403,18.666731 (marker B) and this is the reason for ZERO_RESULTS when you try to create a route without stopovers.
This is also confirmed in the official documentation:
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.
https://developers.google.com/maps/documentation/directions/intro#Waypoints
I hope this explains your doubt!

Related

Google Maps API results vs place results return different names

I am using google maps to provide directions to multiple locations within a website. Users are in Japan, but are non-Japanese, so results should be in English.
In certain examples, even when the name is in the query parameter, a link like this location, returns an alternate Japanese place name (主教座聖堂牧師館), instead of "St. Andrew's Tokyo."
This link is dynamically generated, so I can change the parameters if need be, but I can't figure out how to force results that look more like this, without hardcoding the entire link. Here is what builds the URL:
//handle directions links; send to Apple Maps (iOS), or Google Maps (everything else)
var iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
$body.on('click', 'a.tsml-directions', function(e){
e.preventDefault();
var directions = (iOS ? 'maps://?' : 'https://maps.google.com/?') + $.param({
daddr: $(this).attr('data-latitude') + ',' + $(this).attr('data-longitude'),
saddr: 'Current Location',
q: $(this).attr('data-location')
});
window.open(directions);
});
I've had a look at your sample URL https://www.google.com/maps?daddr=35.6603676,139.7444553&saddr=Yotsuya,%20Shinjuku,%20Tokyo%20160-0004&q=St.%20Andrew%27s%20Tokyo.
I understand that your intention is getting a directions on Google Maps. In the aforementioned URL you specify parameters for origin saddr and destination daddr, the q parameter shouldn't affect directions in this case. So, the destination address is just coordinate 35.6603676,139.7444553. When I reverse geocode this coordinate I get the 'Japan, 〒105-0011 Tōkyō-to, Minato-ku, Shibakōen, 3 Chome−6−18 主教座聖堂牧師館' address as shown in Geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D35.660368%252C139.744455
The 主教座聖堂牧師館 corresponds to premise address component and I suspect it is not translated to English in Google database, because web service call with language set to English returns this component in original language as well
https://maps.googleapis.com/maps/api/geocode/json?latlng=35.6603676%2C139.7444553&language=en&key=YOUR_API_KEY
If your destination should be St. Andrew's, use it as a destination parameter.
And the most important part: Google has Google Maps URLs as an official, recommended and documented method to construct URLs. I would suggest using this API in order to create your directions URLs. These URLs are cross-platform, so there is no need to create different URLs for iOS, Android or web browser.
Your example will convert into
https://www.google.com/maps/dir/?api=1&origin=Yotsuya,%20Shinjuku,%20Tokyo%20160-0004&destination=St.%20Andrew%27s%20Tokyo&travelmode=driving
The result is shown in the screenshot
Your code might be something like
$body.on('click', 'a.tsml-directions', function(e){
e.preventDefault();
var directions = 'https://www.google.com/maps/dir/?' + $.param({
api: "1",
destination: $(this).attr('data-location'),
travelmode: "driving"
});
window.open(directions);
});
Note I don't specify origin parameter as it is optional and in this case it should be interpreted as my current location.
I hope this helps!

Get Segment/Polyline id from maps

Hi i try to find if the google maps or the HERE nokia maps have a static segmentation of the roads and an associated id and where i can find this information. I try to rich information by Rest api from both maps type but i don't find it. Instead with the javascript api i see that i can edit the maps or create, but what i want is to query a server or a database's maps in the way that i can use the latitude and longitude information as key for research (or the address string) and i will get the information from where is the location (so address or lat/long) and in what segment/polyline of the street the location is.
Thanks all!
I think you will need to look at a RESTful API rather than JavaScript:
For the HERE Platform:
To get an address for a Lat/Lng or vice-versa use the Geocoder API
To get an road shapes for a Lat/Lng use the Enterprise Routing API
You will need to register to get access to the documentation, but you can see the APIs in action using the API Explorer e.g. Geocoder Routing
The getlinkinfo endpoint of the Enterprise Routing API could be useful. For example, the URL below ( replace YOUR_APP_ID and YOUR_TOKEN of course)
http://route.st.nlp.nokia.com/routing/6.2/getlinkinfo.json?app_idYOUR_APP_ID&app_code=YOUR_APP_CODEg&waypoint=52.53086,13.3846&linkattributes=shape
Returns the following link info about a line segment:
{
"Response":
{
"MetaInfo":
{
"MapVersion":"2013Q2",
"ModuleVersion":"0.2",
"InterfaceVersion":"4.2",
"Timestamp":"2013-12-12T12:45:47.035Z"
},
"Link":[
{
"_type":"PrivateTransportLinkType",
"LinkId":"+931447247",
"Shape":[
"52.5309486,13.38447",
"52.5310516,13.38482"
],
"SpeedLimit":13.89,
"DynamicSpeedInfo":
{
"TrafficSpeed":6.94,
"TrafficTime":3.7,
"BaseSpeed":13.89,
"BaseTime":1.9
},
"Address":
{
"Label":"Invalidenstraße",
"Country":"DE",
"State":"Berlin",
"County":"Berlin",
"City":"Berlin",
"District":"Mitte",
"Street":"Invalidenstraße"
}
}
]
}
}

Google places details API call return NOT_FOUND for an existing autocomplete reference

I have a problem maybe someone had the same issue.
I am calling google places autocomplete api call.
Then i am presenting the user with the results and he can select the place.
Base on the selection i am making places details call and retrieve the details of the place.
My problem is that some cases the details service return NOT_FOUND. the full response looks something like this
{\n \"debug_info\" : [],\n \"html_attributions\" : [],\n \"status\"
: \"NOT_FOUND\"\n}\n
Based on google api documentation, NOT_FOUND for place details is:
NOT_FOUND indicates that the referenced location was not found in the Places database.
But i got this Reference just 1 sec ago from autocomplete service call!
Anyone has the same problem?
Thanks,
Noam
There are two indexes here, one for the autocomplete suggest and one for the map details. You are seeing the results of the two indexes being updated at different times. If you supply the address in question, I can confirm with the appropriate teams, or you can just wait a couple of days for the indexes to come back into sync.
It could also be due to the fact that the business is closed.
https://developers.google.com/maps/documentation/places/web-service/search-find-place#id-errors
I had a similar issue when using the Find Place endpoint. I would get a successful response and a place_id returned and then calling the Details endpoint would return a NOT_FOUND error.
After adding business_status to the fields on my initial request to the FindPlace endpoint would return:
GET https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=gtdc.org&inputtype=textquery&languagecode=en&fields=place_id,business_status&key={{googlePlacesApiKey}}&locationbias=circle:{{radius}}#{{latitude}},{{longitude}}
Response:
{
"candidates": [
{
"business_status": "CLOSED_PERMANENTLY",
"place_id": "ChIJ7buuHhrhwogR_eWFgXkNyjY"
}
],
"status": "OK"
}
Essentially you just have to ignore any results where the status is CLOSED_PERMANENTLY as these will not work on the details endpoint.
Unfortunately there doesn't seem to be any way of returning the business_status on the Autocomplete endpoint but might be the same issue you are seeing.

Get exact geo coordinates along an entire route, Google Maps or OpenStreetMap

Suppose I have a route defined from one town to another. From the Google Maps API I can recover a route between the two. However, the route returned from Google is a driving route that includes geo-coordinates only at places where there is another step in a leg (for example, where I have to turn from one highway to another).
What I need is geo-locations (lat/long) along the entire route, at specific intervals (for example, every 1/4 mile or 100m).
Is there a way to accomplish this via the Google Maps API / web services?
Or would the OpenStreetMap database be the way to do it?
Kind regards,
Madeleine.
OSRM gives you routes with road geometries as they are in the OpenStreetMap database. For example, you can get the route as GPX (and post-process this file if you want). This would look like the following:
GET http://router.project-osrm.org/viaroute?hl=en&loc=47.064970,15.458470&loc=47.071100,15.476760&output=gpx
Read more: OSRM API docs.
Since the accepted answer is outdated and does not work anymore, here is how all nodes along a road can be queried using the route service from Project OSRM.
Given an arbitrary number of lon,lat pairs.
For Instance the following three (in Berlin):
13.388860,52.517037
13.397634,52.529407
13.428555,52.523219
The route-service calculates the fastest route between these points and its possible to return all nodes along the road using the following query:
http://router.project-osrm.org/route/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?alternatives=false&annotations=nodes
This returns a json response containing node IDs of all the nodes along the route. The result should look something like this:
{
"routes": [
{
...
"legs": [
{
"annotation": {
"nodes": [
2264199819,
2045820592,
21487242,
...
]
}
To receive the lat,lon coordinates of the nodes OverpassAPI can be used.
[out:json];
(
node(264199819);
node(...);
node(...);
...
);
(._;>;);
out;
Here is a sample request using overpass-turbo: http://overpass-turbo.eu/s/toe
It's simply google.maps.DirectionsService().route() method. You need to pass the service request and then a callback which executes upon completion of the service request.
https://developers.google.com/maps/documentation/javascript/directions
While not used as API, here: https://www.nmeagen.org/ one can create "Multi-point line", set the distance between points and download route (coordinates) as CSV.
Adding to the Marlio's answer.
You can use Google Maps Directions API itself.
For a given origin and destination, in the JSON output, look for following:
"polyline" : {
"points" : ""
}
You can use a decoder to get the coordinates from the polyline.:
https://github.com/emcconville/google-map-polyline-encoding-tool
Or. you can use the googleway package in R to decode the same.
https://cran.r-project.org/web/packages/googleway/googleway.pdf
I am not sure how to set the resolution to your desired level though.But the resolution in the API output is really good.

google directions doesn't return any routes when using certain waypoints

I'm using google directions in order to get a route with waypoints. I have the name of the waypoints from an previous call to the Places Api. The problem is that if I make this call:
https://maps.googleapis.com/maps/api/directions/json?origin=46.779704,23.577261&destination=46.564423,23.768673&waypoints=optimize:true|Belvedere,RO|Cheile+Turzii,RO&units=metric&sensor=false
it returns a route. But if Cluj-Napoca National Theatre is added to waypoints and the call looks like this:
https://maps.googleapis.com/maps/api/directions/json?origin=46.779704,23.577261&destination=46.564423,23.768673&waypoints=optimize:true|Belvedere,RO|Cheile+Turzii,RO|Cluj-Napoca+National+Theatre,RO&units=metric&sensor=false
it doesn't work. The response has no results. {
"routes" : [],
"status" : "ZERO_RESULTS"
}
Can anyone please help me understand why isn't this working?
Ps: with Cluj-Napoca+International+Airport,RO added instead of Cluj-Napoca+National+Theatre,RO waypoint it works.
You can try adding the coordinates of the waypoint, instead of adding the name of them.