Get address using Geocoder in android

I tried to get the address of a specific place by providing static geo-coordinates. I could not get the address. Maybe someone can help. I just need to check if this function works for me.

Here is my snippet.

Geocoder geocoder = new Geocoder(AddressSimulator.this, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(1.352566007, 103.78921587, 1); System.out.println("Addresses size"+addresses.size()); 

The address size is obtained as zero. I tried with several other geocoordinates, but the address size always returns as 0. Experts, kindly help me solve this problem.

Expecting valuable help / suggestions,

Best regards, Roni

+4
source share
3 answers

Try using one of google or rpc geocoder. For Google maps, you need to get a key from Google.

for a geocoder, they respond only to one request for every 15 seconds from the same ip.

 string geocoderUri = String.Format("http://maps.google.com/maps/geo?q={0},{1},{2}&output=csv" + "&key= < Your Key > ", street, city, state); 

or

 string geocoderUri = string.Format("http://rpc.geocoder.us/service/rest?address={0},{1},{2}", street, city, state); 
+3
source

Try it. He will provide you with the street, region, country name. Also see this document; here you can find other methods.

http://developer.android.com/reference/android/location/Address.html

 try { Geocoder geo = new Geocoder(this.getApplicationContext(), Locale.getDefault()); List<Address> addresses = geo.getFromLocation(latitude, longitude, 1); if (addresses.isEmpty()) { addres.setText("Waiting for Location"); } else { if (addresses.size() > 0) { addres.setText(addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName()); //Toast.makeText(getApplicationContext(), "Address:- " + addresses.get(0).getFeatureName() + addresses.get(0).getAdminArea() + addresses.get(0).getLocality(), Toast.LENGTH_LONG).show(); } } } catch (Exception e) { e.printStackTrace(); // getFromLocation() may sometimes fail } 

Hope this helps ....

+2
source

Make sure you have INTERNET security permissions set in your AndroidManifest.xml. You must have INTERNET permission to search. I know that you do static lat, long search, but if you want to make lat and long from GPS, you will also need to add ACCESS_FINE_LOCATION permission to enable GPS.

+1
source

Source: https://habr.com/ru/post/1335447/


All Articles