Google Distance Matrix API arrival time - android

I am trying to get the arrival time parameter for the Google Distance Matrix API and I don't understand how to pass data to it. I am trying to make an app to show me what time to leave from somewhere to arrive on time to another place. Does just getting the information in the API violate their terms of usage?
example: https://maps.googleapis.com/maps/api/distancematrix/json?origins=Pawtucket+Rhode+Island&destinations=North+Attleboro+Massachusetts&arrival_time=Dec+5+2015+8+PM&key=YOUR_KEY

Although my answer is a little late for the original post, hopefully it'll still be useful to others... As per the Google Maps APIs Documentation:
arrival_time — Specifies the desired time of arrival for transit requests, in seconds since midnight, January 1, 1970 UTC. You can specify either departure_time or arrival_time, but not both. Note that arrival_time must be specified as an integer.
I suggest doing a calculation in Excel to calculate the number of seconds since 1970 - it can easily get a bit messy, so it's a shame that there's no more 'user-friendly' way to pass the date.
Additionally, I'm not certain whether the arrival_time parameter will definitely work for you - I wanted to use it myself using a call to DistanceMatrix through the JavaScript API and there, it requires a Premium Plan account, but perhaps it's okay directly through the DistanceMatrix API.
Also, the JavaScript DistanceMatrix API states that the arrival_time has to be in the future, which makes sense.

Related

How to get distance between two points from waze

i am developing an app in android that must recieve the distance between two points from the user after traveling between them, and that input must be validated, for that i'm thinking of using an API to get the information and make the validations later. I know that it's not the op to ask the user to enter that kind of input, but that's not on me.
For example, if the distance between point A and point B is 13 km according Google Maps Distance Matrix API, i got from the waze api like 18 km. The approach of the app is one about transport so i would prefer to use waze information because it's more accuarate in terms of road traffic.
So, there's any way to take the distance between two points from waze?
more exactly, this one:
Any help would be appreciated
PD: sorry for bad english
I'm not certain whether you're still looking for an answer, but in theory you could call the Waze routing server in the same way as the Waze Live Map calls it.
The following URL is the request sent to the Waze routing server when I calculate the route between Antwerp and Brussels in Belgium.
https://www.waze.com/row-RoutingManager/routingRequest?from=x:4.4024643+y:51.2194475&to=x:4.3517103+y:50.8503396&at=0&returnJSON=true&returnGeometries=false&returnInstructions=false&timeout=60000&nPaths=1&clientVersion=4.0.0&options=AVOID_TRAILS:t,ALLOW_UTURNS:t
Note: make sure to properly encode this URL when using a script. Those colons and commas might cause issues otherwise.
To calculate the length of a route, you'll need to go through all the traversed road segments and make a sum of the length fields (expressed in metres, if I'm not mistaken).
Do note that the results will differ from time to time as Waze includes historical traffic data in its results and will decide to make detours, which may not be wanted for your use case.
I would also strongly suggest to look into the legal status of doing this, though I suspect it won't be a big issue if you're not using this data to make a competing service or 'forget' to mention you're using Waze data to calculate things.

Get multiple directions with one request with Directions API

This might sound weird, but is there a way to request multiple directions with only one call to the Directions API ?
I'm asking this because I need to calculate a lot of routes at the same time, and I recently saw this :
Free up to 2,500 requests per day.
$0.50 USD / 1,000 additional requests, up to 100,000 daily, if billing is enabled.
2,500 requests per day seems to be ok, but as I said I need to calculate a LOT of routes at the same time (up to 50 I think), so 2,500 is way too small.
Here is why I need to calculate these routes:
I need to get multiple routes from multiple departures points but with the same arrival point (for example route from B to A, route from C to A etc), to find which route is faster (but I need to save all the routes). I am currently requesting every single route with AsyncTasks and it is working fine, but it costs too much requests.
Please share if you have any idea on how I could limit the number of requests, and thank you in advance
You may try to use the parameter alternatives, if it is set to true, it specifies that the Directions service may provide more than one route alternative in the response.
Here is example of request that use alternatives parameter
https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&alternatives=true&key=YOUR_API_KEY
Just take note that providing route alternatives may increase the
response time from the server.
For more information, you can check this SO questions:
Adding multiple directions requests together Google Maps API
Google Maps API to get bus route

Limiting Google Play Games API Calls

In my game I use Google Play Game for Achievements and Leaderboards.
I've just noticed (by logging into the Google API Console), that performing a simple action such as displaying a leaderboard, results in 2 API calls. I would have thought this would be only 1.
I'm simply calling the leaderboard like so:
public void displayLeaderBoard(){
if (getGameHelper().isSignedIn()){
if (leaderboardIntent==null){
leaderboardIntent = Games.Leaderboards.getLeaderboardIntent(getApiClient(), leaderboardID);
}
startActivityForResult(myLeaderboard, 1);
}
}
Note it is still 2 API calls even when pressing the leadeboard button a 2nd time (therefore not creating a new 'leaderboardIntent').
Also, when submitting a high score, it uses 3 API calls (one for submitting, then again it calls displayLeaderboard() to show the player her/his new high score.
The thing here is if I then exit back to the app and submit the score again, it uses another 3 API calls. The documentation states:
Both the Android and iOS client libraries will know not to send a
player's score to the server if your score isn't as good as one you
recently submitted.
I know I could simply store a copy of the high score in sharedPreferences and then not submit it if it's not high enough, but I'm not sure about this - what if the device has multiple accounts set up for example.
I would be grateful if someone with more knowledge/experience of the Play Games API could confirm if the number of API calls I'm seeing is correct and how this relates to quote above, or whether there is something more I should be doing in my code?
The number of calls you are seeing could very well be correct. For many APIs, each request has a "cost" related to it. Which means where a read request to a certain API might cost you 1 call, a write request might cost you 5 (just assuming). Hence, depending on the requests you are making your number of calls are going to differ compared to the number of requests made. For example, try this tool to calculate Youtube API quota cost. Unfortunately I couldn't find any such tool or documentation for Play Games Services API but I hope this makes my point clear.
For optimizing your code to perform it's best, take a look here and try to optimize your code to follow Best Practices as much as you can.

Why is google places api giving me zero results?

I'm trying to develop a location based app using google places, but repeatedly get ZERO_RESULTS on every query.
{
"html_attributions" : [],
"results" : [],
"status" : "ZERO_RESULTS"
}
I intially tried with the URL from my code, using the the lat and lon of Atlanta, GA:
https://maps.googleapis.com/maps/api/place/search/json?location=33.7489,-84.3881&radius=50&keyword=coin|numismatic|silver|gold|dealer|pawn&sensor=false&key=
Then tried something a bit more generic and ubiquitous (Mickey D's) to no avail...
https://maps.googleapis.com/maps/api/place/search/json?location=33.7489,-84.3881&radius=50&keyword=mcdonalds&sensor=false&key=
and then even more generic. This returns results, but erroneous (somewhere in Africa)...
https://maps.googleapis.com/maps/api/place/search/json?location=33.7489,-84.3881&radius=50&type=bank&sensor=false&key=
I know my key is valid, since im not getting request denied and i know my structure is correct since I'm not getting Invalid Request. Anyone know what I'm doing wrong? Thank you in advance
I am receiving one result for the first query, zero for the second and 20 for the third. If I increase the radius from 50 meters to something a bit more realistic like 5000 meters, I receive many more results on the first two queries.
I also noticed that you are trying to filter by multiple keywords which is currently not supported by the Google Places API and is also a likely reason to reduce the number and quality of results returned.
There is a feature request for this in the Places API issue tracker here. Please click the 'star' icon to be notified of future changes, and to let us know you are interested in seeing it resolved.
You should also never post your API key publicly as it is directly linked to your Google account and you are responsible for its use. Please login to the Google APIs Console and generate a new key to avoid users stealing your key and abusing it.
I tried your query with my API key and I get no response either.
I tried to increase the radius and still no result.
I have not used the keyword before, try using type instead. I don´t think there is anything wrong with your query, the problem is that google does actually return 0 result for that query.
One possible reason is that you exceeded the limit of number of requests. Google places api has a limit of 1,000 free requests per 24 hour period. You can extend limit to 150,000 requests per 24 hour period without any payment. But you will have to add your credit card information. Google says that it is only to verify your identity, not to charge you.
If you pay, you can increase the limit more than that.
This information is added on 08/02/2017. Limits may change in time.
In my case, it's the wrong coordinates. Don't use LatLongs from Google Search. Only use the ones which are retrieved from Places API.
Adding my answer even though it's pretty late: I got zero results quite often when I was using locationbias and setting just a single point.
I ended up using circle with a radius of 2000 meters and started getting results consistently
Example: circle:radius#lat,lng, mentioned in the docs here: https://developers.google.com/maps/documentation/places/web-service/search-find-place#maps_http_places_findplacefromtext_mca-sh

Creating a random lat/long coordinate that is positioned in a physically reachable location

I have an application that generates some number of tokens around the current location of the user using a certain distance radius. The user will then have to run to some of those locations. The problem is that some tokens can be created in a lake,forest,ocean, or some other physically unreachable location. As a quick fix I just generate extra tokens and increase the proximity distance that determines if a user reached a certain location. I now want to improve this so that each token is located at a reachable location.
The only solution I have been able to come up with is using the Google Directions API to determine a path from the user to the token and use the last coordinate in the polyline as the new reachable location of the token. My problem with this is that I potentially have to post up to 30 requests to the Directions service simultaneously and I am worried that I might hit the query rate limit. I have not found anything definite about query rate limit.
So my question is whether anyone knows of a better solution or can give any input on the Directions query rate limit? Waiting 1 second between each request and forcing the user to wait up to 30 seconds is not a reasonable solution. Thanks.
UPDATE
Using the solution that I described in the question does produces an OVER_QUERY_LIMIT, even if I wait 1 second between each request. Other then that the logic was sound and tokens that got a request thru were appearing in walk reachable locations.
You can calculate the distance between two lat/lon with Location.distanceBetween(). This is a static convenience API call. There's no limit on number of calulations.
Usage limits
Use of the Google Directions API is subject to a query limit of 2,500 directions requests per day. Individual directions requests may contain up to 8 intermediate waypoints in the request.
Google Maps Premier customers may query up to 100,000 directions requests per day, with up to 23 waypoints allowed in each request.
You might want to take a look into the Maps premier customer so you don't hit the limit too fast. If your app becomes popular I bet you can get an higher limit.
One way would be to see if you can see the elevation to see if it's a cliff or not. However just seeing if it's a lake or not seems to be quite hard. Might be some kind of gps lookup service out there except Google Maps.
If you just want to know the distance between locations just use Location.distanceTo() or static distanceBetween()
Getting the info if it's a road or not is another question.
After some 8 hours I finally got something working. So using the fact that each request can have up to 8 waypoints I can technically ask directions to 9 locations in one request. Here's what I am doing now:
Generate 9 random locations at a time. Pass the locations to my DirectionsComputer which returns the polyline path that goes through all 9 coordinates as a list of coordinates. Then I pick 9 location from the path and set them as the locations of my tokens. Now all my tokens are semi-randomly generated, always appear on a road, and I only need to do 4 consecutive requests to generate 36 tokens.
There are some cases where a few tokens are bunched together. For example, the coordinates which are originally located in the ocean get moved to the same beach. But for the most part, all my tests showed the tokens spread apart and I could tweak the rest.

Categories

Resources