2013-10-20 36 views
0

我使用這個代碼:地理編碼地址適用於平板電腦,但無法在手機上

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

這完全適用於平板電腦,但使我對mobile.Stuck此異常這個從過去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

我的猜測是Geocoder無法在您的手機上工作。一個很常見的問題。這可能會導致你的地址爲空。 LogCat中是否存在java.io.IOException:Service not Available消息? – cYrixmorten

+0

我正在使用mapOnClickListener(),所以我得到經緯度,然後我不知道爲什麼它會去異常?順便說一句 – jason

+0

爲什麼地址是空的? – jason

回答

1

,其只對獲得空值,因爲它沒有找到位置。 1)在您的設備中檢查GPS設置和EPO設置,如果您的設備是新的。 2)只需重新啓動您的設備..

+1

謝謝我前段時間也一樣。你知道如何在帶箭頭指示器的彈出窗口中獲得listview嗎? – jason

+0

你是說用箭頭列表視圖對話框? –

+0

像這樣http://handytechplus.com/wp-content/uploads/2013/04/facebook-apps-for-mobile-phones.jpg這裏是我的問題:http://stackoverflow.com/questions/19415303/listview -toggle-與動畫樣的Facebook – jason

相關問題