[英]GoogleMap (Android) projection visible region not updated after orientation change?
[英]LatLang value of the physical center in the visible GoogleMap region considering mercator projection
我想計算屏幕中間的圓的中心和半徑,半徑是可見區域寬度的一半。
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();
}
對於感興趣的任何人,我都可以通過以下方式解決它:我使用GoolgeMap.getProjection()開始計算圓心的像素位置以及圓上一點的像素位置。 現在,隨着相機的更改,我通過將Point()轉換回LatLang來繪制以該像素位置為中心的圓,其半徑等於中心點與圓上的點之間的距離(以米為單位)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.