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).
Related
Android Geocoder always returns just 1 possible address
val addressesList = Geocoder(this.context).getFromLocationName("Toledo", 5)
Expected : I want to get 5 possible addresses, which has Toledo in their names (
there are
Toledo, USA;
Toledo, Spain;
Toledo, Columbia, etc.)
Actual : Always get 1 address.
The Geocoding API is not meant to be used for ambiguous queries such as "Toledo". It can be expected that the API won't necessarily return all possible matching results.
I suggest using Autocomplete instead to get multiple results for broad inputs. Google's documentation states:
In general, use the Geocoding API when geocoding complete addresses
(for example, “48 Pirrama Rd, Pyrmont, NSW, Australia”). Use the
Places API Place Autocomplete service when geocoding ambiguous
(incomplete) addresses.
Hope this helps!
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.
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
I've just delved into the world of Global Positioning System (GPS) and found the following interesting facts:
1) The Android class android.location.Geocoder always returns null when getting address via reverse geocoding. The code I used is:
Geocoder mGeocoder = new Geocoder(context, locale);
List<Address> addresses = mGeocoder.getFromLocation(latitude, longitude, 1);
if (!addresses.isEmpty()) {
// do something.
} else {
// Display a message regarding no address available.
}
The reason is stated here:
The Geocoder class requires a backend service that is not included in
the core android framework.
So, essentially I would either have to provide offline geolocation data myself for reverse geocoding, or my Android app will have to connect to the Internet and look up geolocation data from Google (via http://maps.googleapis.com/maps/api/geocode/json?latlng= for example). Or use alternative geolocation providers like OpenStreetMap, etc.
2) Android apps like Google Maps requires an Internet connection; while offline provider like TomTom bundled offline geolocation data together with their app so an Internet connection is not needed.
Beside the stated facts above, is there another alternative for retrieving geolocation address without using offline reverse geographic data or using an Internet connection?
If you have some experience with geocoding and reverse geocoding in Android, then please post your thoughts.
Thanks.
There is at least one way for each.
For reverse-geocoding, you let the user mark the geolocation of the address himself using gps.
For geocoding, you let the user hunt down a set of coordinates and then you have him read the street name and the address he finds himself at.
There are few offline libraries available to reverse Geocode offilne. Suggest you to go through these libraries.Personally i have not used these libraries.Let me know if you still face any problems.
https://developers.arcgis.com/android/
Sample code for link:
https://github.com/Esri/arcgis-runtime-samples-android/tree/master
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