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
Differencebetween Min Sdk Version/Target Sdk Version VS. Compile Sdk Version
Failed to Load Appcompat Actionbar with Unknown Error in Android Studio
Android API 21 Toolbar Padding
Android:Difference Between Invisible and Gone
How to Install Trusted Ca Certificate on Android Device
How to Prevent Screen Capture in Android
Open Application After Clicking on Notification
Android Background Music Service
Android Difference Between Two Dates
How to Customize Listview Using Baseadapter
CSS Media Query - Soft-Keyboard Breaks CSS Orientation Rules - Alternative Solution
How to Set My App as the Default Sms App
Overriding the Home Button - How to Get Rid of the Choice
How to Refresh App Upon Shaking the Device
Android: Broadcast Receiver for Screen on and Screen Off
How to Return a Result (Startactivityforresult) from a Tabhost Activity