问题
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)
Thanks and regards, Anass
回答1:
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
回答2:
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" />
回答3:
Try updating Location first. Like below
locationManager.requestLocationUpdates(bestProvider, 20000, 1, this);
refer to here.
来源:https://stackoverflow.com/questions/7109240/service-not-available-geocoder-android