Geocoder API usage limit query - android

I am using Geocoder "getFromLocation" API provided as part of Google SDK in my Android application (Link https://developer.android.com/reference/android/location/Geocoder.html) to get location address details. The input parameters fed to this API are latitude, longitude which are obtained from "getLastKnownLocation" API of Location Manager.
I would like to know if there is any API usage limit per day for Geocoder "getFromLocation" API provided by Google as this API does not ask for any API KEY?
Any input on this will be very helpful. Thanks

Related

How to use Google geocoding API?

I have an Android application and I am using the Google geocoding API to get GPS coordinates for an address. Currently I am using the following URL which works correctly:
http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
The problem is, will the above API continue to work after the Google's 'new pricing changes' starting July 16, 2018? According to the Google API documentation here, https://developers.google.com/maps/documentation/geocoding/intro#GeocodingResponses, the correct way to perform geocoding is using the following format:
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
I have tried using the suggested format (created a project, enabled billing, enabled the Places and Maps APIs, created an API key, added security to the key so that only my app can access the key) but when I use the suggested format I get the error,
This IP, site or mobile application is not authorized to use this API
key
Reading other questions on StackOverflow, I found the following suggestions, among others:
Creating a server key and using it instead of the API key
Not adding restrictions to the API key
Using the first format of the API request (without the API_KEY)
Wait for 10 minutes until the new KEY becomes active
I tried all of them except 1 and none works. Regarding solution #1, according to the documentation, the API needs an API key so I cannot see why a Server key would work.
Solution 2 is risky, solution 3 is not certain that it will continue to work with the pricing changes and solution 4 does not work either (I waited for hours without success).
I even created a new API KEY and added no restrictions to it and I got a limit exceeded error.
Can anyone provide any help on this?
Based on your comment above then the quickest approach would be to reverse geocode the address with Geocoder:
if(Geocoder.isPresentt()){
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses;
addresses = geocoder.getFromLocationName(addressName, 3);
for(Address address : addresses){
Log.d(TAG,"Lat:" + address.getLatitude() +", Lng: " + address.getLongitude());
}
}
Using a proxy service (Solution #1) is the way to go if you are restricted to using the google Geocoding API.
Your app is being denied because google has no way of knowing what app is making the request with just the API key. If you look at the available API's, some say "for Android" and "for iOS", these are the ones that you can restrict and use natively.
Using a proxy will work (your assumption it won't is wrong) because you can restrict your API key to the IP of your service, and then require authorization from your app to use the proxy endpoint. This will protect your API key from being stolen and abused.

Reduce usage of Google Places by using the GeoCoding API in Android/iOS

According to the maps optimisations guide it is possible to reduce usage of Google Places by using the GeoCoding API to retrieve a place location by place Id.
Geocoding API
If your application handles user-typed addresses, the addresses are sometimes ambiguous (incomplete, misspelled, or poorly formatted). You can disambiguate addresses using Autocomplete. Then, use the place IDs to get the place locations.
Mobile
Maps
For mobile applications, use Maps SDK for Android or Maps SDK for iOS when displaying a map. The mobile SDKs are free of charge and have unlimited quota. Use Maps Static API or Maps JavaScript API when requirements rule out using the mobile SDKs.
Is such optimisation possible using Android?
The Geocoder in Android Location package doesn't expose any method to retrieve an address from a placeId only from lat,long or name:
List<Address> getFromLocation(double latitude, double longitude, int maxResults);
List<Address> getFromLocationName(String locationName, int maxResults);
List<Address> getFromLocationName(String locationName, int maxResults, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude);
Javascript Code:
// This function is called when the user clicks the UI button requesting
// a geocode of a place ID.
function geocodePlaceId(geocoder, map, infowindow) {
var placeId = document.getElementById('place-id').value;
geocoder.geocode({'placeId': placeId}, function(results, status) {
if (status === 'OK') {
if (results[0]) {
map.setZoom(11);
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
infowindow.setContent(results[0].formatted_address);
infowindow.open(map, marker);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
The native Android API geocoder doesn't support getting addresses by place ID. Unfortunately, Google Maps Android SDK doesn't provide built-in Geocoder neither. The feature request exists for a long time, but it looks like it doesn't have high priority:
https://issuetracker.google.com/issues/35823852
So, to use place ID in requests you are stick to REST API. There is a Java client library for Google Maps API Web Services that you can find on github:
https://github.com/googlemaps/google-maps-services-java
You can use this library to call Geocoding API from your Java code in Android.
GeoApiContext context = new GeoApiContext.Builder()
.apiKey("AIza...")
.build();
GeocodingResult[] results = GeocodingApi.newRequest(context)
.place("ChIJHzwQtJeLGGARxaSLI71pDSY").await();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
System.out.println(gson.toJson(results[0].addressComponents));
Note that API key for web services must be different from an API key that you used in Android app, because web services don't support Android app restriction.
I hope this helps!

Is there any direct method (except URL) for Reverse geocoding by place id in android?

I am trying to get Google Address by Reverse Geocoding by placeId not by LatLng.
Though I found its web-service -https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
but in android, Geocoder does not have any function which can give me address by accepting placeId. I am using 10.0.1 version of google play services location library.
You can get all the details about a place by using place_id with below api
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=YOUR_API_KEY
put your place_id and Api_key and you will get the result

Difference between Android in built Geocoder and Google Geocoding API

Can anybody tell me exact difference between Android Geocoder and Android Google Geocoder API
As far I know, Android Geocoder is platform in-built class and gives less result compare to APIs and also less reliable.
Is there any hard limit/quota for in-built Geocoder class ?
Android Geocoder is built in class and has no quota limits.
Geocoding API is a http request and has 2500 QPD quota. Geocoding seem to be more reliable.
Geocoder is just "a class for handling geocoding and reverse geocoding".
According to the documentation:
"The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists."
Google Geocoding API is the API, the backend service in the platform. You can use it without Geocoder class.
Reference: https://developer.android.com/reference/android/location/Geocoder

Geocoding API vs Geocoder

In my application I need to use the geocoding, but I am not quite clear which method to use. Until yesterday I added the parameters to the URL maps.googleapis.com/maps/api/geocode/json?address=myparameter&sensor=false, but Google blocked my requests for a day, making the application crash because it did not return any results from the request for geocoding.
Now I am using the Geocoder class that does the same thing and also I have seen that you can create and use an API key for Geocoding.
Which method do you recommend to use? What is the difference between the two methods, apart from the limitations of the requests?
If you need to use a map in your app, you should use the API called: Google Maps Android API v2.
If you need to manage geocoded data (address to lat/lng or viceversa) then enable Geocoding API and start using the class Geocoder.
For example (lat/lng to address):
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(gps.getLatitude(), gps.getLongitude(), 1);
Geocoder is a built-in API in the Android framework that is free. Geocoding API is a rest API that is paid. Geocoder uses a different search stack internally and this leads to different results comparing to the Geocoding rest API. The Geocoding rest API works better than Geocoder normally but has usage limits and the implementation is bigger.
Users of free API have following limits:
2,500 requests per 24 hour period.
5 requests per second.
You can include API key in web-request also like:
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=API_KEY
Not sure about android Geocoder class, maybe someone else can help you out in that matter. But i assume same limits would apply.
Geocoder API is built into the system and it's easy to use. From my experience, it's working in most cases, although:
in some cases it fails and throws grpc failed IOException
Non-fatal Exception: java.io.IOException: grpc failed
at android.location.Geocoder.getFromLocation(Geocoder.java:136)
it may not be even available on some devices (use isPresent() method to verify this).
With above, I don't think Geocoder API is super reliable, so if geocoding is a critical part of your app, you may look into other options (like Google's Geocoding API, which is not free).

Categories

Resources