Given an origin and destination, I want to get the location x minutes into that route; is this possible through the Google Maps API?
Not directly, no.
The closest you could easily get is that you know what legs would have been completed in the required time, and how much of the current leg remains.
Calculating the location of the point that much time into that leg would be more tricky.
Related
I want to find a travel time (including traffic) between two addresses.
Inputs - origin, destination, arrival time, mode of transportation, traffic model (pessimistic, optimistic, best guess)
Output - Travel time
It looks like the Google Distance Matrix API is the API I should be using for this except that I am not able to add an input of arrival time for driving. I am prompted to add a departure time. When the transportation mode is transit I am able to enter an arrival time.
Is this a limitation of the distance matrix API? Is there a paid for version or another work around for this?
As of today (January 6, 2019) arrival time for driving is not supported. Here is the relevant portion of the help file for the API's directions method:
:param arrival_time: Specifies the desired time of arrival for transit
directions. Note: you can't specify both departure_time and
arrival_time.
:type arrival_time: int or datetime.datetime
The key being that arrival time is only used for transit directions and not driving directions. When I use mode='driving' and an arrival_time, I get and error that ends with:
raise googlemaps.exceptions.HTTPError(response.status_code)
googlemaps.exceptions.HTTPError: HTTP Error: 400
When I change this to a departure_time, the function call works just fine.
Explicit answers to the questions:
Is this a limitation of the distance matrix API?
Yes.
Is there a paid for version or another work around for this?
No. Your only option is call the API with a guess for the departure time, find the travel time and then iterate until the arrival time converges.
instead of using the google direction matrix try to use google map direction API, it will give you best results with the time distance and traffic update, see GOOGLE MAP DIRECTIONS API docs.
You need to use the Google map distance matrix API, which get input as source latitude, longitude and destination latitude, longitude. It will return the json file contains the source address, destination address, distance in km and time with traffic and without traffic.Below is link follow it
https://developers.google.com/maps/documentation/distance-matrix/intro
There is also a limit of this API, it allows only 2500 hits per day
For example I have a bus route and bus stops. I would like to set up something where I can check time estimates until bus arrives at a stop (bus pings location). Is this possible with Google or anything else?
Yes #JasonFel ,you can do that using Google Map service "Waypoints in directions", where you can setup your route of bus from start to end and the stops will be your waypoits, so you can easily find the distance and the approx time between two points, you just need to go through this link,
https://developers.google.com/maps/documentation/javascript/examples/directions-waypoints
Waypoint Demo: `https://jsfiddle.net/9nb42yhf/1/`
I have a number of target points on the map and a source location. I need to find the target point closest to the source location. The trick here is that "closest" means the shortest route. I can't use a simple crow fly distance.
This is essentially a one-to-many routing problem. I can get the answer by running a routing API call for each pair of points but that would be too slow and will blow up API usage.
Is there a way to do it with a single request using Google Maps API (I am ok paying for it if necessary)?
If yes, then what are the limits to the number of points, the request frequency, etc?
If no, is there another service that can do it?
Say I have a lot of points (thousands). Is there a way to upload them somehow and only use the source location in my requests?
You should take a look to Distance Matrix Service
You can specify a starting point and an end point (even intermediate waypoints), then get the distance in kilometers / miles by route.
To answer your questions :
Is there a way to do it with a single request using Google Maps API (I am ok paying for it if necessary)
Yes you can, just use the service given below
If yes, then what are the limits to the number of points, the request frequency, etc?
To quote the Usage limits and requirements :
The following usage limits are in place for the Distance Matrix service:
Maximum of 25 origins or 25 destinations per request; and
At most 100 elements (origins times destinations) per request.
Requests are also rate limited. If too many elements are requested within a certain time period, an OVER_QUERY_LIMIT response code will be returned.
Say I have a lot of points (thousands). Is there a way to upload them somehow and only use the source location in my requests?
I'm not sure what you really want, but you can define a point as "source location", then load it (from SQL, KML etc...), then load the targets and call the service to find which one is the closest.
Google Maps API has any way to get the street coordinates of an location?
Is simple: I just want to get the nearest street coordinate. To got this i need, for example, all coordinates that compose a street.
Are there something like this?
You may use the directionService.
Pass the given address(or location) as origin and destination to directionsService.route() and use the travelMode DRIVING . The response should contain the nearest street.
Demo: http://jsfiddle.net/doktormolle/W3VGN/
I found this (ReverseGeocoding in v3): https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding
Since this thread is old I suppose this could be useful.
These answers are all old, and Google has rearranged the maps API significantly since the answers.
In 2018, the best way to turn a location (long, lat) into a "point on road," is to use the snap-to-road or nearest-road service:
https://developers.google.com/maps/documentation/roads/snap
Note that this API charges a cent per API call, and can take up to 100 distinct points per call. If latency and complexity aren't problems, if you need to answer this question on a client, you could build a server that collects up to 100 requests from different clients, makes one request to Google, and then returns the request data back to the appropriate clients. (For this use, make sure to use nearest-road, not snap-to-road.)
Also, currently, Google Maps has a $200 per-month statement credit available, which may make smaller uses of this API not actually end up costing much (or anything at all.)
I need to get all the nearby public transit information within certain distance from a given location. The type of public transit can be either bus, train, etc..
Here is what I meant:
If I use Google Map to query "Transit Stop near a Location (e.g. Bugis Street Singapore)", then it will return us all the nearby Transit Stop that I want. Like the one shown in the picture. But I need its API to get those details out. (such as bus service No, bus stop ID, etc. as shown in the picture). But I couldn't found any.
Here is what I've tried
I have tried using the Google Map Nearby Place API to search for a place with the type of transit_station, bus_station, train_station,etc... But they all return Zero Result. I could only use this API to search for Nearby Place of Interest, but not nearby transit.
I've also check Google Transit API, but I only found API to insert transit data to Google but Not to extract it out. I think Google didn't publicize the transit API yet.
Additional Information
I have check the site Gothere.sg. And confused How? because they able to detect the nearby transit. Is it only because they specify the direction "From-To".
I have read a pretty similar question on Detecting nearby transit. Perhaps It is not yet possible if we use Google APIs.
But nothing is impossible for me
Last Resort
As Last resort, I also check with the provider, publictransport.sg. I hack around with the API. And found out that it can provide me with a transit stop with some coordinate. But it lack a nearby API which found on Google Map.
So one workaround I could think of at the moment, is to use the provider in this case was publictransport.sg which give me the Stop ID and its coordinate. To do this, First, I have to translate the location name using the Google GeoCoding API into Coordinate then I have to create my own nearby calculation to find the nearby station by comparing the searched Coordinate against all the station coordinate that the provider have.
Now, it is possible for me, but very painful :-)
Back to the Question:
Is there a way to retrieve all transit stop data from a given location (either using Google Maps API or Any other API)? and How did u do that?
Thanks
At least thanks for reading my lengthy question. I appreciate any help from you.
Well, you could use the places-API to find the nearest transit-stops, it works fine for me for the given location.
Just do a request with the parameters:
location (latlng-object of the given location)
radius(radius to search for in meters)
types(array of valid types, e.g. ['bus_station','subway_station'])
Checkout the fiddle: http://jsfiddle.net/doktormolle/aZrvs/
For retrieving further details(bus service No, bus stop ID) I don't have any good idea right now.
There should be a way, those data on maps.google.com will be retrieved by using AJAX, so there is a ressource. But as long as there is no public API to fetch those results it would not be legal to use this ressource.
Adding &output=json to your initial query (http://maps.google.com/maps?q=transit%20stop%20near%20New%20Bugis%20Street%20Singapore&output=json), is not a legal way to get this information?
You can still enumerate all of Bus Service Number, Bus Stop ID (Station Names) after getting the google-places-api details, as #Dr.Molle: said.
Open the webpage of detail['result']['url'], and then XPath the string of bus ID list.
Below is an example to get Taipei's bus Info around a location (latitude, longitude). More detail implementation see https://github.com/MikimotoH/gisTools/blob/master/google_place.py
places = get_web_json(
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?' +
'key=%s&location=%f,%f' % (apikey, lat, lng) +
'&rankby=distance&language=zh-TW&types=bus_station')
if places['status'] == 'OK':
for result in places['results']:
placeid = result['place_id']
detail = get_web_json(
'https://maps.googleapis.com/maps/api/place/details/' +
'json?key=%s&placeid=%s' % (apikey, placeid) +
'&language=zh-TW')
station = detail['result']['name']
loc = detail['result']['geometry']['location']
buspage = get_webpage(detail['result']['url'])
tree = lxml.html.document_fromstring(buspage)
bus_elm = tree.xpath("/html/body/div[1]/div/div[4]/div[4]/div/div/div[2]/div/div[2]/div[1]/div[2]/div/div/div[2]/div/table/tr/td")[0]
buses = list(filter(lambda s: len(s.strip()) > 0,
bus_elm.text_content().strip().split()))
yield (station, float(loc['lat']), float(loc['lat']), buses)
The Transitland APIs can answer your question. For example, try using the Transitland v2 REST API stops endpoint like this:
https://transit.land/api/v2/rest/stops?lat=xxx&lon=xxx&radius=1000&apikey=xxx
More information on the endpoint parameters and response at https://www.transit.land/documentation/rest-api/stops