我想计算屏幕中间圆的中心和半径,半径是可见区域宽度的一半。
visibleRegion.latLngBounds.getCenter()
或者
cameraPosition.target
当我缩小很多时,中心的值与物理中心有偏移。
在下图中,我计算了黑色阴影圆圈如下:
VisibleRegion visibleRegion = mMap.getProjection().getVisibleRegion();
LatLng nearLeft = visibleRegion.nearLeft;
LatLng nearRight = visibleRegion.nearRight;
mCircle.setCenter(visibleRegion.latLngBounds.getCenter());
mCircle.setRadius(distanceFrom(nearLeft.latitude, nearLeft.longitude, nearRight.latitude, nearRight.longitude) / 4);
public double distanceFrom(double lat1, double lng1, double lat2, double lng2)
{
// Return distance between 2 points, stored as 2 pair location;
double dLat = Math.toRadians(lat2 - lat1);
double dLng = Math.toRadians(lng2 - lng1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double dist = EARTH_RADIOUS * c;
return new Double(dist * METER_CONVERSION).floatValue();
}