46

I have a little problem with the geocoder to get latitude and lontitude from an address :

This is my code:

for (Garage g : XMLGarage) {
List<Address> address;
address = coder.getFromLocationName(
g.getAddress(), 5);
if (address != null) {
Address location = address.get(0);  
g.setLatitude(location.getLatitude());
g.setLongitude(location.getLongitude());
...

The error is :

08-18 14:28:56.026: WARN/System.err(359): java.io.IOException: Service not Available
08-18 14:28:56.026: WARN/System.err(359):     at 
android.location.Geocoder.getFromLocationName(Geocoder.java:178)
08-18 14:28:56.026: WARN/System.err(359):     at 
com.amt.android.garage.Garage.postData(Garage.java:269)
08-18 14:28:56.026: WARN/System.err(359):     at
com.amt.android.garage.GarageForm$2.onClick(GarageForm.java:86)
08-18 14:28:56.026: WARN/System.err(359):     at  
android.view.View.performClick(View.java:2485)
08-18 14:28:56.026: WARN/System.err(359):     at
android.view.View$PerformClick.run(View.java:9080)
08-18 14:28:56.036: WARN/System.err(359):     at  
android.os.Handler.handleCallback(Handler.java:587)
08-18 14:28:56.036: WARN/System.err(359):     at
android.os.Handler.dispatchMessage(Handler.java:92)
08-18 14:28:56.036: WARN/System.err(359):     at
android.os.Looper.loop(Looper.java:130)
08-18 14:28:56.036: WARN/System.err(359):     at 
android.app.ActivityThread.main(ActivityThread.java:3683)
08-18 14:28:56.036: WARN/System.err(359):     at
java.lang.reflect.Method.invokeNative(Native Method)
08-18 14:28:56.036: WARN/System.err(359):     at
java.lang.reflect.Method.invoke(Method.java:507)
08-18 14:28:56.036: WARN/System.err(359):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-18 14:28:56.046: WARN/System.err(359):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-18 14:28:56.046: WARN/System.err(359):     at dalvik.system.NativeStart.main(Native    
Method)
Bijoy Thangaraj
  • 5,434
  • 4
  • 43
  • 70
Anass
  • 6,132
  • 6
  • 27
  • 35
  • I'd like to point out that even though this question is marked as a duplicate (which is correct), the top answer given on this question is a valid, possible solution that the other question does not offer. – d60402 Apr 16 '13 at 16:07
  • Please reboot your device first, it might be enough to fix your problem. – Neo Mar 17 '18 at 19:05

3 Answers3

100

There is a problem recently with android devices and the geocoder not working: http://code.google.com/p/android/issues/detail?id=38009

A reboot seems to fix the issue

Somatik
  • 4,723
  • 3
  • 37
  • 49
  • 90
    suggesting a reboot is a terrible solution. Even more terrible of a solution when it's the correct one. Worked for me. – djunod Dec 18 '12 at 12:01
  • We had this on 4 devices with different android versions. Have never seen this issue afterwards. (probably related to google play services update) – Somatik Dec 19 '12 at 15:34
  • Wowwww!!! Work for me too... Next, how it work without 'Reboot' device? – HATCHA Jan 10 '13 at 04:47
  • 2
    Had this problem with 2 tablets. Upgraded with Google play services and Geocoder did not work. Reboot fixxed the issue. Come on google... – Patrick Jackson Jan 30 '13 at 16:19
  • Rebooting the device works... it must be an Android Bug – Kasas Feb 05 '13 at 17:23
  • Incredible! Rebooting the Samsung Galaxy Tab 2 was the solution. Thanks a lot! – Pascal Mar 27 '13 at 18:06
  • rebooting fix the issue, but the problems comes back after a while. Can anyone help? – Pascal Apr 02 '13 at 08:50
  • 8
    OK.. I just try to edit the post but my edit was rejected. I just want to share my experience: rebooting fix the problem just.. temporary. The bug comes back again. As an alternative, one can use Google Map API. I made a full working example availalbe here: http://stackoverflow.com/questions/9272918/service-not-available-in-geocoder/15853124#15853124 – Pascal Apr 07 '13 at 13:56
  • Yup solved. But why it happens? I mean it can directly impact on application and indirectly on android developer. Even it is the Android bug :( – Husnain Iqbal Jul 03 '13 at 16:38
  • For avoiding the reboot and solving the "Service not available" **Geocoder problem** you need to **set the Project Build Target to API 16**. In Eclipse: Right Click Project -> Build Path -> Configure Build Path -> Android -> Project Build Target. – Umberto Jul 08 '13 at 10:51
  • lol strangely worked for me :) – Meriam Aug 14 '13 at 14:47
  • 2
    i think this is a silly solution, but it's worked! – Yohanim Aug 11 '14 at 12:33
  • 1
    I should be amazed that in 2016 I still see this problem on devices... – Richard Le Mesurier Mar 09 '16 at 14:33
  • 2
    @RichardLeMesurier 2017 here... it can still happen with an API 25 target – alexgophermix Feb 15 '17 at 21:57
13

You will get this error occasionally if the GeoCoding provider fails and is unable to geocode your location.

See these relevant posts:

Geocoder.getFromLocation throws Exception

Geocoder.getFromLocation throws IOException on Android emulator

If this is not the case, make sure you have the Internet permission in your Manifest:

<uses-permission android:name="android.permission.INTERNET" />
Community
  • 1
  • 1
hooked82
  • 6,336
  • 4
  • 41
  • 46
  • Service not Available - Geocoder Android when i get this error in some cooked roms i wrote this library i hope could be useful. https://github.com/dnocode/gapis – dnocode Mar 15 '15 at 15:44
0

Try updating Location first. Like below

locationManager.requestLocationUpdates(bestProvider, 20000, 1, this);

refer to here.

j0k
  • 22,600
  • 28
  • 79
  • 90
pretty angela
  • 2,241
  • 1
  • 19
  • 8