地理编码器地址适用于平板电脑但不适用于移动设备

时间:2013-10-20 17:57:03

标签: android geocoding google-maps-android-api-2

我正在使用此代码:

String address = "";
     Geocoder geoCoder = new Geocoder( getBaseContext(), Locale.getDefault());
         try {
           List<Address> addresses = geoCoder.getFromLocation(latitude ,longitude , 1);
           if (addresses.size() > 0) 
              {
              for (int index = 0; 
              index < addresses.get(0).getMaxAddressLineIndex(); index++)
               address += addresses.get(0).getAddressLine(index) + " "; }
                           }
         catch (IOException e) {        
             e.printStackTrace();
           }   
 googleMap_v2.animateCamera(CameraUpdateFactory.zoomTo(15));
          current_location.setText("Latitude:" +  latitude  + ", Longitude:"+ longitude );
          current_address.setText("current Address :" + address ); 
          googleMap_v2.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("current status")); 
        }}   

这在平板电脑上非常有效,但在移动设备上给我这个例外。从过去的72小时开始就无法解决这个问题。如果有人能说出我应该添加的内容,我真的很感激吗?提前谢谢。

例外:

FATAL EXCEPTION: main
 java.lang.NullPointerException
    at com.maps.maps.MainActivity$1.onMapClick(MainActivity.java:442)
    at com.google.android.gms.maps.GoogleMap$.onMapClick(Unknown Source)
    at com.google.android.gms.maps.internal.h$a.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:297)
    at bor.a(SourceFile:93)
    at maps.af.q.b(Unknown Source)
    at maps.ap.bo.b(Unknown Source)
    at maps.ap.bk.onSingleTapConfirmed(Unknown Source)
    at maps.bt.g.onSingleTapConfirmed(Unknown Source)
    at maps.bt.i.handleMessage(Unknown Source)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:4945)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

仅用于获取空值,因为它找不到位置。 1)在您的设备中检查gps设置和波形设置以及您的设备是否为新设备。 2)只需重新启动你的设备..