地理编码地址转换为长期转换(APP FORCE CLOSES)

时间:2015-04-10 20:07:36

标签: android eclipse google-maps geocoding google-geocoder

我是Android开发的新手,我正在开发一个Android应用程序,我将地址转换为纬度和经度。我正在使用地理编码器。但是,当我打电话给那个功能app力量关闭。 这是我的代码段

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();
        }
    }

这是我的logcat

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 个答案:

答案 0 :(得分:0)

添加

<uses-library android:name="com.google.android.maps" /> 

到您的AndroidManifest.xml文件,位于应用程序标记

下面