我想在 map 中添加一个按钮,使 map 以用户当前位置为中心,但只有当用户在 map 中导航并且他的当前位置不再显示在 map 上时,才应激活该按钮。
为了检测导航,我使用了 onTouchEvent
方法。
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
Log.e("Touch", Integer.toString(event.getAction()));
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
touchStarted = true;
} else if (action == MotionEvent.ACTION_MOVE) {
if (event.getPointerCount() > 3)
moveStarted = true;
return true;
}
return true;
}
但我如何检测到我的当前位置不再显示在屏幕上?
最佳答案
其实我找到了一个更好的解决方案:
private void CheckVisibility(Marker myPosition)
{
if(googleMap != null)
{
//This is the current user-viewable region of the map
LatLngBounds bounds = googleMap.getProjection().getVisibleRegion().latLngBounds;
if(bounds.contains(myPosition.getPosition()))
//If the item is within the the bounds of the screen
else
//If the marker is off screen
}
}
关于android - 如何检测我的位置不再显示在 map 上(导航后)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19529968/