4
我有下面的代码提供纬度和经度后能得到完整的地址字符串。但它一直都是例外。我不知道为什么这个代码没有返回地址。请帮忙。谢谢。的Android - 地理编码没有得到地址字符串
private String getCompleteAddressString(double LATITUDE, double LONGITUDE) {
String strAdd = "";
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
strAdd = strReturnedAddress.toString();
Log.w("My Current loction address", "" + strReturnedAddress.toString());
} else {
Log.w("My Current loction address", "No Address returned!");
}
} catch (Exception e) {
e.printStackTrace();
Log.w("My Current loction address", "Canont get Address!");
}
return strAdd;
}
logcat的
04-05 09:28:44.217: I/SurfaceTextureClient(4578): [STC::queueBuffer] this:0x55815618, api:1, last queue time elapsed :225623 ms
04-05 09:28:44.218: I/SurfaceTextureClient(4578): [0x55815618] frames:2, duration:225.699997, fps:0.008861
04-05 09:28:44.265: V/Provider/Setting(4578): from settings cache , name = sound_effects_enabled value = 0
04-05 09:28:44.290: W/System.err(4578): java.io.IOException: Service not Available
04-05 09:28:44.342: W/System.err(4578): at android.location.Geocoder.getFromLocation(Geocoder.java:139)
04-05 09:28:44.342: W/System.err(4578): at com.beproject.ourway.Panic.getCompleteAddressString(Panic.java:70)
04-05 09:28:44.343: W/System.err(4578): at com.beproject.ourway.Panic.getLocation(Panic.java:102)
04-05 09:28:44.343: W/System.err(4578): at com.beproject.ourway.Panic.onOptionsItemSelected(Panic.java:158)
04-05 09:28:44.343: W/System.err(4578): at android.app.Activity.onMenuItemSelected(Activity.java:2546)
04-05 09:28:44.343: W/System.err(4578): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:971)
04-05 09:28:44.343: W/System.err(4578): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
04-05 09:28:44.344: W/System.err(4578): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
04-05 09:28:44.344: W/System.err(4578): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
04-05 09:28:44.344: W/System.err(4578): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:523)
04-05 09:28:44.344: W/System.err(4578): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:100)
04-05 09:28:44.344: W/System.err(4578): at android.view.View.performClick(View.java:4091)
04-05 09:28:44.345: W/System.err(4578): at android.view.View$PerformClick.run(View.java:17072)
04-05 09:28:44.345: W/System.err(4578): at android.os.Handler.handleCallback(Handler.java:615)
04-05 09:28:44.345: W/System.err(4578): at android.os.Handler.dispatchMessage(Handler.java:92)
04-05 09:28:44.346: W/System.err(4578): at android.os.Looper.loop(Looper.java:153)
04-05 09:28:44.346: W/System.err(4578): at android.app.ActivityThread.main(ActivityThread.java:4987)
04-05 09:28:44.346: W/System.err(4578): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 09:28:44.346: W/System.err(4578): at java.lang.reflect.Method.invoke(Method.java:511)
04-05 09:28:44.346: W/System.err(4578): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
04-05 09:28:44.346: W/System.err(4578): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
04-05 09:28:44.347: W/System.err(4578): at dalvik.system.NativeStart.main(Native Method)
04-05 09:28:44.347: W/My Current loction address(4578): Canont get Address!
什么是堆栈跟踪和e.getMessage()? – 2015-04-05 03:58:18
这可以帮助:http://stackoverflow.com/questions/4761052/why-is-android-geocoder-throwing-a-service-not-available-exception – 2015-04-05 04:01:13
我没有得到这个问题的答案:( – 2015-04-05 04:02:50