如何确定在当前可查看区域中是否显示了地理点?

dl.*_*dl. 10 android android-mapview

说我的Android应用程序中有mapview控件.如果我知道某个纬度和经度存在地标,我如何确定该地标当前是否可在用户屏幕上查看?有没有一种方法可以获得可见区域左上角和右下角的坐标?

Pau*_*aul 6

像这样的东西可以解决问题.

private boolean isCurrentLocationVisible()
    {
        Rect currentMapBoundsRect = new Rect();
        Point currentDevicePosition = new Point();
        GeoPoint deviceLocation = new GeoPoint((int) (bestCurrentLocation.getLatitude() * 1000000.0), (int) (bestCurrentLocation.getLongitude() * 1000000.0));

        mapView.getProjection().toPixels(deviceLocation, currentDevicePosition);
        mapView.getDrawingRect(currentMapBoundsRect);

        return currentMapBoundsRect.contains(currentDevicePosition.x, currentDevicePosition.y);

    }
Run Code Online (Sandbox Code Playgroud)


sky*_*man 5

您可以将GeoPoint投影到Point并检查它是否为(0,屏幕宽度)为(0,屏幕高度)

请参阅:https://developer.android.com/reference/com/google/android/gms/maps/Projection.html