【问题标题】:How to detect my position is no longer shown on map (after navigation)?如何检测我的位置不再显示在地图上(导航后)?
【发布时间】:2015-07-24 21:29:05
【问题描述】:

我想在地图中添加一个按钮,使地图以用户当前位置为中心,但只有当用户在地图中导航并且他的当前位置不再显示在地图上时,它才应该被激活。 为了检测导航,我使用了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;
}

但是我如何检测到我的当前位置不再出现在屏幕上?

【问题讨论】:

    标签: android android-maps-v2


    【解决方案1】:

    其实我找到了更好的解决方案:

    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
        }
    }
    

    【讨论】:

      【解决方案2】:

      关于如何做到这一点,我最好的想法是首先找出相机(即用户可以看到的东西)指向什么。然后,用 LatLng 计算出相机视野中的确切内容,并将其与用户的当前位置进行比较。

      1. 获取当前 LatLng、Zoom 和 Tilt 的 CameraPosition 数据 - https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/CameraPosition
      2. 找出屏幕上实际显示的内容。在这里查看起点:https://developers.google.com/maps/documentation/android/views#the_camera_position
      3. 通过 LocationProvider 从 LocationListener 获取当前位置。
      4. 进行更多数学运算以查看用户的位置是否在当前屏幕上可见。

      另一种建议是仅使用包含的“我的位置”按钮作为 API 的一部分。它始终可见,但与 Google 地图应用程序相同,因此您的用户将已经了解如何与之交互。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多