i have a address and wants to find the latitude and longitude for that address...anybody know how can we get lat long from address in android...
i am using this code
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));
but i got this exception
09-02 17:46:56.086: ERROR/Exception(1724): Service not Available
09-02 17:46:56.086: ERROR/Exception(1开发者_开发技巧724): 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)
what i did wrong?
You are getting service not available error. You need an actual device, not emulator. The GeoCoder documentation says:
The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform.
This issue page says:
Are you guys using this code on the Android 2.2 emulator? I'm also getting this error on the emulator but it works on the actual device (nexus one - android 2.2)
Just installed CyanogenMod 6 alfa and now GeoCoder works fine. I guess it will work on final builds of stock Froyo too.
精彩评论