dl.*_*dl. 10 android android-mapview
说我的Android应用程序中有mapview控件.如果我知道某个纬度和经度存在地标,我如何确定该地标当前是否可在用户屏幕上查看?有没有一种方法可以获得可见区域左上角和右下角的坐标?
像这样的东西可以解决问题.
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)
您可以将GeoPoint投影到Point并检查它是否为(0,屏幕宽度)为(0,屏幕高度)
请参阅:https://developer.android.com/reference/com/google/android/gms/maps/Projection.html
| 归档时间: |
|
| 查看次数: |
6561 次 |
| 最近记录: |