我有一个地址,想要找到该地址的纬度和经度...任何人都知道我们怎么能从android中的地址得到lat ...
我正在使用此代码
Geocoder coder = new Geocoder(getApplicationContext(), Locale
.getDefault());
List<Address> address;
address = coder.getFromLocationName(
"Pallekele International Cricket Stadium,Kandy, 1);
if (address == null) {
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
GeoPoint point = new GeoPoint((int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
但我得到了这个例外
09-02 17:46:56.086: ERROR/Exception(1724): Service not Available
09-02 17:46:56.086: ERROR/Exception(1724): java.io.IOException: Service not Available
09-02 17:46:56.086: ERROR/Exception(1724): at android.location.Geocoder.getFromLocationName(Geocoder.java:159)
09-02 17:46:56.086: ERROR/Exception(1724): at pack.sample.map.SampleMapApplication.onCreate(SampleMapApplication.java:38)
09-02 17:46:56.086: ERROR/Exception(1724): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-02 17:46:56.086: ERROR/Exception(1724): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-02 17:46:56.086: ERROR/Exception(1724): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-02 17:46:56.086: ERROR/Exception(1724): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-02 17:46:56.086: ERROR/Exception(1724): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-02 17:46:56.086: ERROR/Exception(1724): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 17:46:56.086: ERROR/Exception(1724): at android.os.Looper.loop(Looper.java:123)
09-02 17:46:56.086: ERROR/Exception(1724): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-02 17:46:56.086: ERROR/Exception(1724): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 17:46:56.086: ERROR/Exception(1724): at java.lang.reflect.Method.invoke(Method.java:521)
09-02 17:46:56.086: ERROR/Exception(1724): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-02 17:46:56.086: ERROR/Exception(1724): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-02 17:46:56.086: ERROR/Exception(1724): at dalvik.system.NativeStart.main(Native Method)
我做错了什么?
答案 0 :(得分:1)
您收到服务不可用错误。您需要实际设备,而非模拟器。 GeoCoder documentation说:
Geocoder类需要后端 服务不包括在内 核心android框架。地理编码器 查询方法将返回一个空的 如果没有后端服务,请列出 平台。
这issue page说:
你们是否在Android 2.2模拟器上使用此代码?我也在模拟器上收到此错误,但它适用于实际设备(nexus one - android 2.2)
刚刚安装了CyanogenMod 6 alfa,现在GeoCoder工作正常。我想它也适用于股票Froyo的最终版本。