android - 如何检测我的位置不再显示在 map 上(导航后)?

标签 android android-maps-v2

我想在 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/

相关文章:

java - 为什么我得到一个 null 对象?

android - 如何在Android中使用Scala类

android - 如何缩放相机以覆盖android googlemap中的路径?

java - Android 谷歌地图 v2、MAP_TYPE_NONE 和黑色方 block

android - 根据用户移动 android googleMaps v2 更新折线

android - SQLite更新行错误没有这样的列

java - 如何从内部 AsyncTask 访问 fragment

java - 不推荐使用 Android setOnMyLocationChangeListener

java - 如何使用 retrofit2 接收 Json 数组 ("result")

Android map 加载错误