Android: Reverse Geocoding - Getfromlocation

Android: Reverse geocoding - getFromLocation

The following code snippet is doing it for me (lat and lng are doubles declared above this bit):

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);

How can i get address from coordinates in android studio

If you want to get address from coordinates like you said, you should use:

val addresses: List<Address> = geoCoder.getFromLocation(latitude, longitude, 1)

val result = addresses[0].locality

geoCoder.getFromLocationName() is used when you want to know latitude and longitude from string address.

Also, for retrieving your location's latitude and longitude you can use the following:

fusedLocationClient.lastLocation.addOnSuccessListener {location: Location? ->
if(location != null) {
val myLatitude = location.latitude
val myLongitude = location.longitude
}
}

Reverse Geocode a lat/long coordinate using Geocoder on a HMS device

Your question is that when using the native Android API getFromLocation on an HMS device, the system prompts that the API call times exceed max requesting limit.

The possible cause is that you frequently initiated requests when the network condition was poor. To ensure proper use of resources, the system has limited the resource usage. You are advised to restart HMS Core (APK) or the device, and initiate requests when the network condition is good, as well as ensure that no more than 10 requests are initiated in a short period of time.

Thanks for your feedback. This issue will be rectified in Location Kit 5.0.2, which will be released on September 15, 2020.

Update:

The new version of Location Kit 5.0.2.301 is here, modified the description of the setMaxWaitTime method in the LocationRequest class, preventing slow first location callback due to incorrect settings.

GeoCoder getFromLocation address never contains Business name

I have concluded that Geocoding is simply not viable for real-time place look-up. While there is a getFeatureName() field, it seems to only return anything useful for precise GPS coordinates so dropping a pin will almost never result in a useful fetaure name.

I have switched to Google Places API instead for business name look-ups, and for consistency's sake, am also now using nearbysearch from Places API for searching instead of Geocoding.



Related Topics



Leave a reply



Submit