2012-06-08 36 views
0

當我在Google地圖上繪製兩個標記(來源&目的地)時,我想要動態獲得兩個經緯度點。在哪裏我可以使用這些經緯度來進一步實施。如何在android中動態獲取lat/long?

請幫我,我該如何得到它。

+0

http://android-example-code.blogspot.in/p/map-api-in-android.html and .... http://stackoverflow.com/a/10597160/1289716 – MAC

回答

1

嘗試下面的代碼。可以幫助你.. :)

mapView.setOnTouchListener(new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      // TODO Auto-generated method stub 
      GeoPoint p = null; 

      if (event.getAction() == MotionEvent.ACTION_UP) { 
       p = mapView.getProjection().fromPixels((int) event.getX(), 
         (int) event.getY()); 
       mapBackButton.setText(p.getLatitudeE6()/1E6 + "," 
         + p.getLongitudeE6()/1E6 + "Action is : " 
         + event.getAction()); 
       return true; 
       Toast.makeText(
         getBaseContext(), 
         p.getLatitudeE6()/1E6 + "," + p.getLongitudeE6() 
           /1E6 + "Action is : " + event.getAction(), 
         Toast.LENGTH_SHORT).show(); 
      } 
      return false; 
     } 
    }); 

    mapView.dispatchTouchEvent(ev); 

根據你的需要進行編輯。

+0

Tariq,感謝您的迴應,在您的代碼中,如果聲明它變得錯誤,因此無法獲得實際結果。 – Aswin

+0

修改了一點點,我把ACTION_DOWN而不是ACTION_UP,它工作正常。但是,當我拖動地圖到其他位置的觸摸監聽器,如果失敗。 – Aswin

+0

粘貼/編輯我的答案中的最新代碼 –

相關問題