0

In my app Location Service is not returning address and locality for my current lat-long

    List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); 
    for (Address address : addresses) {
       textOut.append("\n" + address.getAddressLine(0));

The above code keeps on running forever while when I just want to display lat-long it works perfectly

vedbhawsar
  • 75
  • 8

1 Answers1

0

Make sure that you have the following uses-permissions added to your manifest xml file.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

The Geocoder class has a static method isPresent(). Does this return true on your device?

Failing that, it may be simply be that no matches were found. See SDK doc . Have you tried with different locations?

Alternatively, you can call the Google Geocode API directly. See the docs here: Google Geocode API

Smalesy
  • 591
  • 1
  • 7
  • 20
  • I have those permissions in place as the location manager is giving me correct lat-long – vedbhawsar Oct 29 '14 at 11:45
  • I updated the answer above. Have you tried using different lat-longs? And if so, is the result always the same? – Smalesy Oct 29 '14 at 12:31
  • yes I have tried with lat-long given in developer's manual i.e. for Amphitheatre location. Eclipse tells me The method isPresent() is undefined for the type Geocoder – vedbhawsar Oct 29 '14 at 13:14
  • Is this the example you are referring to http://developer.android.com/training/location/display-address.html Also, are you using a device or the emulator? – Smalesy Oct 29 '14 at 13:50
  • I am on the emulator and I am following the book _Learning Android, Second Edition by Marko Gargenta and Masumi Nakamura_ – vedbhawsar Oct 30 '14 at 05:49
  • I suspect that I may be Geocoder.getFromLocation() is not supported on the emulator you are using. See this answer: http://stackoverflow.com/questions/5205650/geocoder-getfromlocation-throws-ioexception-on-android-emulator – Smalesy Oct 30 '14 at 09:47
  • you are right its working on physical device. Emulator was the issue. But I didn't get why emulator was not working? its ok. **Thanks For All Your Help :)** – vedbhawsar Oct 30 '14 at 10:07
  • No problem, happy to help. I’ve generally found the Geocoder implementation quite fragmented, works on certain devices but not others. Because of which I tend to use Googles Geocode API in any production code. – Smalesy Oct 30 '14 at 12:30