地理编码地址到经纬度转换(APP FORCE CLOSES)
Posted
技术标签:
【中文标题】地理编码地址到经纬度转换(APP FORCE CLOSES)【英文标题】:Geocode address to lat and long conversion(APP FORCE CLOSES) 【发布时间】:2015-06-16 16:04:23 【问题描述】:我是 android 开发的新手,我正在开发一个 android 应用程序,我在其中将地址转换为纬度和经度。我正在使用地理编码器。但是当我调用该函数时,应用程序强制关闭。 这是我的代码 sn-p
public void getLatLongFromGivenAddress(String address)
double lat= 0.0, lng= 0.0;
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try
List<Address> addresses = geoCoder.getFromLocationName(address , 1);
if (addresses.size() > 0)
GeoPoint p = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
lat=p.getLatitudeE6()/1E6;
lng=p.getLongitudeE6()/1E6;
String lati =String.valueOf(lat);
String longi =String.valueOf(lng);
Log.d("Latitude", ""+lat);
Toast.makeText(getApplicationContext(), lati, Toast.LENGTH_LONG).show();
Log.d("Longitude", ""+lng);
Toast.makeText(getApplicationContext(), longi, Toast.LENGTH_LONG).show();
catch(Exception e)
e.printStackTrace();
这是我的日志
04-11 01:33:45.020: E/dalvikvm(25175): Could not find class 'com.google.android.maps.GeoPoint', referenced from method at.vcity.androidim.Messaging.getLatLongFromGivenAddress
04-11 01:34:03.090: E/AndroidRuntime(25175): FATAL EXCEPTION: main
04-11 01:34:03.090: E/AndroidRuntime(25175): Process: at.vcity.androidim, PID: 25175
04-11 01:34:03.090: E/AndroidRuntime(25175): java.lang.NoClassDefFoundError: com.google.android.maps.GeoPoint
04-11 01:34:03.090: E/AndroidRuntime(25175): at at.vcity.androidim.Messaging.getLatLongFromGivenAddress(Messaging.java:300)
04-11 01:34:03.090: E/AndroidRuntime(25175): at at.vcity.androidim.Messaging.appendToMessageHistory(Messaging.java:272)
04-11 01:34:03.090: E/AndroidRuntime(25175): at at.vcity.androidim.Messaging$2.onClick(Messaging.java:131)
04-11 01:34:03.090: E/AndroidRuntime(25175): at android.view.View.performClick(View.java:4444)
04-11 01:34:03.090: E/AndroidRuntime(25175): at android.view.View$PerformClick.run(View.java:18440)
04-11 01:34:03.090: E/AndroidRuntime(25175): at android.os.Handler.handleCallback(Handler.java:733)
04-11 01:34:03.090: E/AndroidRuntime(25175): at android.os.Handler.dispatchMessage(Handler.java:95)
04-11 01:34:03.090: E/AndroidRuntime(25175): at android.os.Looper.loop(Looper.java:136)
04-11 01:34:03.090: E/AndroidRuntime(25175): at android.app.ActivityThread.main(ActivityThread.java:5047)
04-11 01:34:03.090: E/AndroidRuntime(25175): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 01:34:03.090: E/AndroidRuntime(25175): at java.lang.reflect.Method.invoke(Method.java:515)
04-11 01:34:03.090: E/AndroidRuntime(25175): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
04-11 01:34:03.090: E/AndroidRuntime(25175): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
04-11 01:34:03.090: E/AndroidRuntime(25175): at dalvik.system.NativeStart.main(Native Method)
我应该做哪些改变? 谢谢!
【问题讨论】:
【参考方案1】:添加
<uses-library android:name="com.google.android.maps" />
到您的 AndroidManifest.xml 文件中,在应用程序标签下方
【讨论】:
以上是关于地理编码地址到经纬度转换(APP FORCE CLOSES)的主要内容,如果未能解决你的问题,请参考以下文章