2016-12-26 135 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) –

相关问题