I develop an application and i need to use somehow with google maps.
I tries both:
1.send request to "http://googleapis.com/maps/api........"(with key..).
2.javascript file of googlemaps.
and now I'm stuck with a big question that i cant find any complete answer(from what i understand).
The question:
I need from any user in my application to use the request something like 5-20 times a day(if the user will be very active). I read that there is a limit of 2500 requests a day. This 2500 requests a day is per user?(sound the limit is only for not flooding google..am i right?). if it is 2500 requests for all users so I need much much much more then 2500.
there is a difference for google if I use option 1 or 2?(regular request/javascript file).
Thanks.
If you are talking about a displaying a Google map to a user, then there are no restrictions.
2500 requests/day is the limit for Google Directions API, which is used to create directions that you can get and display for your users (e.g. driving route from point A to point B).
However if the directions you are getting from the Directions API are repeated over and over, you could just save them as an XML file on your server (or the device) and re-use them, that way you can stay inside the 2500 limits.
Related
Let us suppose we have three hotels:
Hotel A (popular in 1 km radius), Hotel B (popular in 2 km radius) and Hotel C (popular in 4 km radius). A car enters and is at some position. These Hotels (or any other place) is added by us and is custom.
Problem is I want to find the hotels which have popularity/influence at my current location.
And I want it to do totally with the help of Google Maps. Is it feasible ? on Android (optional)? Please ELI5.
Google Maps API has a function called computeDistanceBetween. It "returns the distance, in meters, between two latitude/longitude coordinates". Circle has the Center and Radius properties. So you need to calculate the distance between the center of a circle and you current location. If it's less than the radius of the circle, than it means your current location is within the circle.
Simplifying is key
Although I understand your objective (get a list of all hotels near you) I believe your explanation threw many people off guard. You don't need to triangulate positions and calculate radius of circles - not with Google Maps APIs and Services.
All you need to know is if you want a solution for front-end, back-end, or mobile
Google Maps Places API Web Service (back-end)
The Places API has a very useful feature called "Places Nearby". To quote the documentation of this feature:
A Nearby Search lets you search for places within a specified area.
You can refine your search request by supplying keywords or specifying
the type of place you are searching for.
Which looks exactly like what you need, right ?
To make a request from a server to the Places API Web Service looking for nearby places, you can do the following:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&type=restaurant&name=cruise&key=YOUR_API_KEY
Do remember to change the key=YOUR_API_KEY to a valid key field. The example showed will look for restaurants in a radius of 500 meters around the location of -33.8670522,151.1957362.
There are a lot of parameters to this and you can read more about this in the following documentation
https://developers.google.com/places/web-service/search
Google Maps JavaScript API with Places Library (front-end)
If you however don't have a central server or service to make requests for you, making the clients send the requests directly is also an option.
In this case, there is the JavaScript API. The JavaScript API is a client-side friendly API that re-uses some of the Web Service's features.
In this case, you can use the JavaScript API in conjunction with the Places Library for it. According to the documentation, this API allows you to do "Nearby Search Requests":
A Nearby Search lets you search for places within a specified area by
keyword or type
An example of such a request can be seen in a live example in the following link https://developers.google.com/maps/documentation/javascript/examples/place-search
You can read more about the parameters and usage of this API and this library in the following documentation https://developers.google.com/maps/documentation/javascript/places#place_search_requests
Google Maps Android API (mobile)
From the picture you added, I assume your app will be to "use on the go" (perhaps a mobile app), or something similar.
In this scenario, using a web-server or a website could be cumbersome, as by the time you have a response from it, the car is already in another position !
To aid you in this, there is also the Android API. To use it you need to:
Download and Install Android Studio
Add Google Play Services Package (contains APIs you will use)
You can read more about this process here https://developers.google.com/maps/documentation/android-api/start
As for code and examples, I strongly suggest you check out this GitHub repository of samples
https://github.com/googlemaps/android-samples
Our Hotels may not show up on Google Maps
Unless your DeLorean takes you back to the latter half of the 19th century, or you are stuck in an island with hundreds of Meerkats, poisonous pools and a tiger wondering if he should eat you or not, Google Maps will pretty much always show you some hotels where you can spend the night.
PS: kudos++ if someone gets my references :P
Adding Hotels and Places to Google Maps APIs and Services
If this is still not enough however, there is still a way you can fix it. You can add Hotels addresses and Places to Google Maps by using one for the two following methods:
Send Feedback
Use Maps Maker
Send Feedback
The "Send Feedback" feature allows you to send feedback to Google's data teams for review. Once approved, the data is added to Google's database and will be available to all Google's customers. You can do this by following the steps described here https://support.google.com/maps/answer/3094045?co=GENIE.Platform%3DDesktop&hl=en
Please do note however that the review process for your feedback will take some time, so don't expect anything instantaneous !
Use Maps Maker
Alternatively, you can use Maps Maker. This tool allows you to do edits and add information to our Services in a more streamlined manner.
At first, your edits and suggestions will still be reviewed, and it will usually take less than two weeks to get something approved.
However, with time, as more and more of you suggestiogns are approved, you gain reputation, and when you have a lot of reputation, your suggestions will be pretty much automatically added.
Before using it however, make sure you have a look at the list of supported countries.
Also, if language is important, you may want to consider it as well, by checking the list of supported languages.
I really don't want to add anything to Google Maps
Sometimes the whole business is data itself, so giving it out freely is not an option.
In these cases, you will have you own database, which your services will have to check.
In cases like this a custom solution for your system is needed, but in order to suggest a few more ideas, more information is needed.
Hope it helps !
Your approach should use fast approximate calculations without relying on apis, and then api usage can be used to enhance user experience.
You know the coordinates of the car.
You know the coordinates of each of the hotels.
Assign a popularity weight to each hotel based on your criteria or data you have. e.g a hotel having more user reviews or transactions or bookings will have higher influence, or if you want to personalize, a hotel which suits the loggedin user's budget preferences ( based on past data or settings ) will have higher influence. Lets call this popularity value p1,p2..p3 etc.
Find all hotels that lie within a threshold range, say 5kms within current position of the car. This can be done using a geospatial query in any major storage database ( for example if your hotel points are stored in MySQL, or mongodb ), or if you are using a hotel data api, get the nearby hotels,or all hotels of that city, and prune them based on distance from car's current location.
For linear distance between the car C, and the hotels H1, H2... use Haversine formula , this will give you distance between the Car and any hotel along the Earths curvature. ( Actual road distance might vary, as roads are directions aren't straight and involve turns etc). But this will give you a fast approximation of distances D1 between C & H1, D2 between C & H2 etc...
Now decay the popularity score P1...PN of each hotel based on distance between the Car C and the hotel H. For example if hotel H1 has popularity score P1= 90, and hotel H2 has popularity score P2=90, but C <---> H1 distance is 10kms, and C<--->H2 distance is 2kms,
then H2 will have more influence on the current location compared to H1.
A simple formula can be LocationInfluence = PopularityScore/ log(Distance), you can optimize this based on your use case.
Now for the most influential hotels H1,H2,H3... use DistanceMatrix api to find actual driving distance, you can also use google maps directions api for Android or Javascript to show driving directions to the user, from location till the hotel.
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
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.
I am working on an Android app that displays a map, and when the user clicks on it, it takes the Lat/Lng and send them to my Rails server, that does the reverse_geocoding and store the address and the coordinates in the database. Then, the user can see the map with all the places around his location displayed.
I just added the functionality to create the place via the app yesterday, before that I used activeadmin directly in Rails, and everything was working fine. But yesterday, when testing my app, I suddenly got the Google API error :
Google Geocoding API error: over query limit
How is that possible ? I know there is a limit of 2500 request/day but I am far from that number, I did maybe 50 creations yesterday, in a 2 hours period.
It works again when I wait like 30 minutes or so...
For the reverse geocoding I am using Geocoder. Is that possible that Location.near does a request to Google API each time ? Normally it does not request Google servers when Lat/Lng are provided, but it checks only in the database, right ?
Or can it be my app that sends this kind of request to Google servers each time I display the map ?
I am a bit lost here...
Thanks !
Geocoding services also limit based on queries per second as well, which may be the reason for that message.
Geocoder does makes an API call every time you call Location.near("foo") (in order to get the lat/lon of the foo). In combination with geocoding your models, you may be hitting the rate limit.
You may want to try adding some retry logic when the query limit exception is called, or getting the lat/long from your Android app and pass that directly to the query, avoiding the .near geolocation.
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.