0

我正在使用Goggle Maps SDK在手機上製作GPS應用程序。我想添加一個功能,讓用戶只需通過在屏幕上粘貼該點即可獲取特定點的經度和緯度。GPS航點經緯度

一個例子是如果有「這是什麼?」在Google地圖上有類似的功能,但在電話版本上?我將如何在代碼中做到這一點?

+1

因此,如果我理解了您的問題,您的應用中已經有Google地圖,並且您只想查找點擊的緯度/經度,對吧? – Tushar 2013-03-24 01:34:39

+0

是的,該應用程序已經在我的手機上,我希望找到點擊/屏幕上的經緯度 – Hawkhunter 2013-03-24 02:58:27

+0

我仍然感到困惑。您手機上的Google地圖應用程序,還是您的應用程序擁有Google地圖SDK? – Tushar 2013-03-24 04:16:31

回答

0

好的。首先,你需要擴展com.google.android.maps.Overlay並覆蓋onTap方法:

class MOverlay extends Overlay { 
     @Override 
     public boolean onTap(GeoPoint p, MapView mapView) { 
      int latitude = p.getLatitudeE6(); 
      int longitude = p.getLongitudeE6(); 

      // Do whatever you need to do here. 

      return true; // true means we handled the tap 
     } 

} 

然後,你需要將這個疊加到地圖上疊加的列表。假設你的活動延長MapActivity,此代碼應工作:

class MyActivity extends MapActivity { 
    public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      // your code here 

      MapView map = findViewById(R.id.map); // you can change this 

      MOverlay clickCatcher = new MOverlay(); 
      List<Overlay> allOverlays = map.getOverlays(); 
      allOverlays.add(clickCatcher); 
      map.invalidate(); 
      // All done! 
    } 
} 

希望這可以幫助你。祝你好運!

+0

非常感謝您的時間:) 我會實施它也許在週末,看看它是如何去。 – Hawkhunter 2013-03-27 01:00:40