我使用 osmdroid MapView。我需要查找用户位置是否在地图边界内(取决于缩放级别)。
我尝试使用 MapView.getBoundingBox().contain(location).. 但似乎 getBoundingBox() 返回了可见边界。
有没有办法获得原始地图边界(取决于缩放级别)?
谢谢
我使用 osmdroid MapView。我需要查找用户位置是否在地图边界内(取决于缩放级别)。
我尝试使用 MapView.getBoundingBox().contain(location).. 但似乎 getBoundingBox() 返回了可见边界。
有没有办法获得原始地图边界(取决于缩放级别)?
谢谢
您可以使用以下代码找出地图视图西北角和东南角的纬度和经度:
GeoPoint topLeftGpt = (GeoPoint) mapView.getProjection().fromPixels(0, 0);
GeoPoint bottomRightGpt = (GeoPoint) mapView.getProjection().fromPixels(
mapView.getWidth(), mapView.getHeight());
然后,您可以确定兴趣点是否在这些范围内。
对于 v2:
LatLng northwest = (LatLng) mMap.getProjection().fromScreenLocation(new Point(0, 0));
LatLng southeast = (LatLng) mGoogleMap.getProjection().fromScreenLocation(
new Point(mMapView.getWidth(), mMapView.getHeight()));