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.
Related
I am new to mobile development and I undertook some freelance work. Now I am required to display a page with top N nearest places (businesses registered with us).
I am wondering what the best way of going about this is, from my experience it would seem that I would want to do this calculation in my back-end server.
I have a NodeJS server, however, it seems the server will be concurrently doing a lot of other work just verifying JWT tokens and what not, I have seen that android provides a method to easily do these calculations (Location). I have also read that there are some google API's one could use.
The idea I have is that I can pull my places with their lat, long from my database then the user sends lat,long and my server calculates top N results and sends to user.
What would you recommend and why?
Thanks!
The short answer is: Server.
But why?
The job of the server to make it so no one can use the app who is not authorized to do so. Thats one of many jobs anyway. However, you should send your location to the server, the server makes the API call, and returns the N closest locations.
You take that response, parse it, and fill in a view as you would like. With the server doing the heavy lifting, you can then also keeps track of something better, like how many calls, which calls, location of calls, etc etc.
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.
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
I have an android app that is adding places to the google Places API without problem. My app also receives places added by other users.. To my dismay, I realized that when adding a place, there is no way to include an address, only a longitude and latitude. I had suspected that Google would supply an address when the place was requested, but alas, the "vincinity" value is not included in the JSON returned from good on this location.
I suppose I could take the lat and lng and subsequently geocode (reverse-geocode?.. I can't ever keep them straight) the results myself, but was wondering if there was something I was overlooking.. I have read all the Places API docs through several times.. I thought if anyone knew a little trick, they would be on this website (of course).
The 'vicinity' parameter will only be returned after the Place Report Request has been moderated.
Currently only Place Report Requests submitted from a small number of trusted applications are being moderated for integration into Google Places. We are still working on streamlining the moderation process to minimise spam, incorrect and duplicate place results.
The best option would be to reverse geocode the returned lat lng.
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.