2016-12-26 130 views

回答

0

在創建佈局和映射初始化後,在onCreate()中添加以下代碼:

View mapView = getSupportFragmentManager().findFragmentById(R.id.map).getView(); 
if (mapView.getViewTreeObserver().isAlive()) { 
    mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(CENTER, 15)); 
      Point markerScreenPosition = map.getProjection().toScreenLocation(marker.getPosition()); 
      int x = markerScreenPosition.getX(); 
      int y = markerScreenPosition.getY(); 
      if(x == yourValue && y == yourValue){ 
       //your trigger code goes here 
      } 
     } 
    }); 
} 
+0

不按位置我的意思是屏幕位置(x,y)座標,因爲我已經提到過屏幕左下角 – Nobody

+0

我編輯了我的答案。希望這可以幫助。 – tahsinRupam

0

我認爲標記不會自動丟棄。他們由您的代碼處理。例如,您可以在地圖點擊或地圖長按上添加標記。獲取該事件並嘗試修復

+1

它可以通過設置可拖動'.draggable(真)'我想要知道如何觸發一個事件,基於它在屏幕上的位置,就像我已經問過 – Nobody

+0

這樣的情況下,你可以[試試這個](https://developers.google.com/android/reference/com /google/android/gms/maps/GoogleMap.OnMarkerDragListener) –

相關問題