I am using the google maps api in a test version to calculate the travel distance between two or more adresses. Now, usually, this is not a problem at all, considering that the distance matrix does exactly that. But when I try to get the distance between two points, let's say Berlin and New York, seperated by sea, I run into problems, the API returns zero_results. I assume this is because the travel mode is "driving" as by default, yet I can not find a more fitting mode in the documentation. https://developers.google.com/maps/documentation/distance-matrix/intro#travel_modes.
Am I using the wrong product? Is there a travel mode I missed? Hope somebody can help me with this, thanks.
The API call I use is
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Berlin&destinations=New+York&key=MY_KEY
The response I get is
{
"destination_addresses" : [ "New York City, New York, USA" ],
"origin_addresses" : [ "Berlin, Deutschland" ],
"rows" : [
{
"elements" : [
{
"status" : "ZERO_RESULTS"
}
]
}
],
"status" : "OK"
}
The currently supported Travel modes are driving, walking, bicycling and transit. So you would probably choose the transit mode as you obviously can't drive, walk or bicycle from Berlin to NY.
For the transit mode, the supported transit_mode values are bus, subway, train, tram and rail. So again, nothing here that allows for crossing the ocean...
I would assume that these are the only possible travel modes you can get today via the API.
Related
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!
So, there is an "Anthony" small community which showed in GoogleMaps
https://www.google.com/maps/place/Anthony,+WV+24938,+USA/#37.8959703,-80.3407936,15z/data=!3m1!4b1!4m2!3m1!1s0x884c425d36b87e11:0xd99c2e98a2185333?hl=en
My question is - why Google's reverse geocoder doesn't return correct name of that unincorporated community?
For example, if i try to reverse that coordinates 37.895767,-80.330698 which points to the center of "Anthony" it returns "Frankford"-city, which far far away from "Anthony"(see picture).
Similar behavior at maps.google.com - when i point near "Anthony" it shows nothing related to it. See another picture.
Hereis JSON returned from reverse geocoder(json format). And there is no any signs about "Anthony" location. I'm curious...why?
Any thoughts?
P.S. I'm using web-api to obtain reversed geocoded data
https://maps.googleapis.com/maps/api/geocode/json?latlng=37.895767,-80.330698&language=en&key=MY_KEY
This may have something to do with rural naming conventions, given that these places belong to "unincorporated" (region of land that is not governed by its own local municipal corporation, but rather is administered as part of larger administrative divisions) criteria. In your JSON data: "formatted_address": "3853 Anthony Rd, Frankford, WV 24938, USA", notice the the type property which is based on locality and political:
{
"long_name": "Frankford",
"short_name": "Frankford",
"types": [
"locality",
"political"
]
}
This means that Frankford is the recognized locality of Anthony area. There is also a chance that Google Maps are that inaccurate ( it was able to pinpoint the location though) as implied by spherical geometry concepts in Google Docs.
Looking at the response I can see that reverse geocoding returns '3853 Anthony Rd, Frankford, WV 24938, USA' for 37.895767,-80.330698.
According to USPS.com this is a valid address
https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=1&companyName=&address1=3853+Anthony+Road&address2=&city=Frankford&state=WV&urbanCode=&postalCode=&zip=24938
though '3853 Anthony Rd, Anthony, WV 24938, USA' is also recognized as valid
https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=1&companyName=&address1=3853+Anthony+Rd&address2=&city=Anthony&state=WV&urbanCode=&postalCode=&zip=24938
You can report a data problem to Google following:
https://support.google.com/maps/answer/3094088
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.
I am unable to get any results with the Places API when I use a types=transit_station|neighborhood (or any other type included in the table 2 here: http://code.google.com/apis/maps/documentation/places/supported_types.html#table2
Apparently, this is not related to a specific location (I've tried both Milan, Italy and London, GB), so I'm wondering if I'm doing something wrong or if the API is not currently working as expected.
If the above has no solution, I'd be very happy if there was another way of finding the neighborhood of a building (for instance, in this map: http://g.co/maps/hfdke I'd like to be able to find "Fiera Campionaria", "Il Portello" etc).
What you are looking for are sublocality's, this can be confirmed through a Places Autocomplete API request:
Input "Fiera Campionaria" returns "Fiera Campionaria, Milano, Italia" with types "sublocality", "political", "geocode":
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Fiera%20Campionaria&sensor=false&key=your_api_key
Input "Il Portello" returns "Il Portello, Milano, Italia" with types "sublocality", "political", "geocode":
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Il%20Portello&sensor=false&key=your_api_key
Unfortunately a Places API Search request in this area with types specified as "sublocality|political|geocode" does not return these results:
https://maps.googleapis.com/maps/api/place/search/json?location=45.47536640,9.15523110&radius=3000&sensor=false&types=sublocality|political|geocode&key=your_api_key
I have reported this Internally as a bug.
Cheers
Chris
First of all:
Keep in mind that you only can find a place that has been created by somebody.
Also remember that the places-API is experimental.
I also didn't find any place of type neighborhood in Milan or London.
But I find them e.g. in Paris, New York, Washington, so you may test your application there.
What I realized while playing around with the API:
When I define the range to search for by location and radius the results often are very inaccurate.
For example I search for a neighborhood starting by a point in radius of 5km, it will find a neighborhood in 4km but not in 400m.
The results are much more exactly when I search within LatLngBounds
Could anyone explain to me why when I allow HTML5 Geolocation Demos to use my location it always returns New York, however, when I go on my phone it shows my exact position? I am trying to implement a 'current location' function on my website, though I don't know if it is possible.
Thank you
Your phone has a GPS radio that can narrow your location down to within ten or so meters. Your computer (generally) has no such capability. Your browser can use information like your IP address to get close to your actual location, but it can't achieve anything like your phone's precision.
There are a number of pieces of additional information available to your phone that can be used to determine your location more accurately than on a typical wired desktop. Notably:
A GPS receiver
Wi-Fi access points (APs) visible to your phone and the signal strength of each
Cell towers visible to your phone and the signal strength of each
GPS
Generally speaking, GPS when available is likely to give the highest accuracy. With a clear view of the sky, most phones can geolocate you using GPS to within 5 meters or less.
Wi-Fi
Companies like Google/Apple have information matching known AP SSIDs/MAC addresses to geographic locations. A phone is able to send information off to a service (such as Google's geolocation API) about the APs it can see and their signal strength. The service returns an estimate of location based on what it knows about those APs and any proprietary algorithms the service provider uses to determine location based on AP signal strengths.
Cell towers
Much like Wi-Fi information, your phone can send off cell tower visibility/signal strength information to a service which can estimate location based on what it knows about the cell towers under consideration.
Here's an example of what a phone might send off to Google's geolocation service (copied verbatim from the link):
{
"version": "1.1.0",
"host": "maps.google.com",
"home_mobile_country_code": 310,
"home_mobile_network_code": 410,
"radio_type": "gsm",
"carrier": "Vodafone",
"request_address": true,
"address_language": "en_GB",
"location": {
"latitude": 51.0,
"longitude": -0.1
},
"cell_towers": [
{
"cell_id": "42",
"location_area_code": 415,
"mobile_country_code": 310,
"mobile_network_code": 410,
"age": 0,
"signal_strength": -60,
"timing_advance": 5555
},
{
"cell_id": "88",
"location_area_code": 415,
"mobile_country_code": 310,
"mobile_network_code": 580,
"age": 0,
"signal_strength": -70,
"timing_advance": 7777
}
],
"wifi_towers": [
{
"mac_address": "01-23-45-67-89-ab",
"signal_strength": 8,
"age": 0
},
{
"mac_address": "01-23-45-67-89-ac",
"signal_strength": 4,
"age": 0
}
]
}
Note that some of the information in the example is even more detailed than what I've described. But you probably get the idea about the kind of hints regarding location that a typical modern phone provides that a desktop machine can't.
From my personal experience, Wi-Fi/Cell tower based geolocation is not as accurate as GPS, but can be quite good. For example on a base model iPad without a GPS chip, I can often get accuracy within 50 meters based off Wi-Fi/cell towers alone. In more densely populated Wi-Fi areas (e.g. in the city) I imagine the accuracy is even better and will continue to get better over time.