簡體   English   中英

谷歌地圖可見區域內圓的半徑

[英]Radius of a circle inside the Google map visible region

我想獲得內接在屏幕上可見區域的矩形內的圓的半徑......谷歌地圖 sdk 僅提供近左、遠左、近右和遠右......有了這個,我可以得到以下內容:

在此處輸入圖片說明

但我需要的是:

在此處輸入圖片說明 .

我一直在使用以下代碼:

    public static double getMapVisibleRadius(GoogleMap map) {
    VisibleRegion visibleBounds = map.getProjection().getVisibleRegion();
    LatLng center = visibleBounds.latLngBounds.getCenter();
    LatLng northEast = visibleBounds.nearLeft;
    // r = radius of the earth in km
    double r = 6378.8;
    // degrees to radians (divide by 57.2958)
    double ne_lat = northEast.latitude / 57.2958;
    double ne_lng = northEast.longitude / 57.2958;
    double c_lat = center.latitude / 57.2958;
    double c_lng = center.longitude / 57.2958;
    // distance = circle radius from center to Northeast corner of bounds
    double r_km = r * Math.acos(
            Math.sin(c_lat) * Math.sin(ne_lat) +
                    Math.cos(c_lat) * Math.cos(ne_lat) * Math.cos(ne_lng - c_lng)
    );
    return r_km; // radius in meters

}

這是在第一張圖像中提供圓的半徑。

我也嘗試使用距離位置的 distancebetwwen 來找到 farleft 和 Nearleft 的中點......我一直在計划找到地圖中心之間的距離,從而找到了中點。 但是,我無法獲得該點的 Latlng .. 所以我無法繼續..

VisibleRegion visibleBounds = mGoogleMap.getProjection().getVisibleRegion();
    float[] distanceBetweentopAndBottomLeftCorners = new float[1];
    float[] distanceBetweenMiddleOfLeftAndCenterOfVisibleRegion = new float[1];
    LatLng topLeftCorner = visibleBounds.farLeft;
    LatLng bottomLeftCorner = visibleBounds.nearLeft;
    Location.distanceBetween(topLeftCorner.latitude, topLeftCorner.longitude, bottomLeftCorner.latitude, bottomLeftCorner.longitude, distanceBetweentopAndBottomLeftCorners );
    float centerOfVisibleRegionLeftToScreen = distanceBetweentopAndBottomLeftCorners [0]/2;
   // Here I am unable to proceed since the above calculated value is a float and not Latlng. My idea was to find the distance between this value and center of visible bound;

任何幫助表示贊賞。

您正在測量左上角和左下角坐標之間的距離,因此它為您提供垂直距離(到底部)。 要測量水平距離,您應該使用“farLeft 和farRight”或“nearLeft 和nearRight”坐標(從左到右)。

VisibleRegion visibleBounds = mGoogleMap.getProjection().getVisibleRegion();
float[] distanceBetweenLeftAndRightCorners = new float[1];
LatLng topLeftCorner = visibleBounds.farLeft;
LatLng topRightCorner = visibleBounds.farRight;
Location.distanceBetween(topLeftCorner.latitude, topLeftCorner.longitude, topRightCorner.latitude, topRightCorner.longitude, distanceBetweenLeftAndRightCorners );
float thisIsWhatYouNeedInMeters = distanceBetweenLeftAndRightCorners [0]/2;

通過這種方式,您將獲得屏幕頂部或屏幕底部的距離,但我想所有水平距離都將相同,因此您可以獲得所需的距離。

如果您想准確地測量下面的坐標,您可以傳遞給 distanceBetween()。 正如我所提到的,結果不會有所不同。

LatLng leftCenter = new LatLng((visibleBounds.farLeft.latitude + visibleBounds.nearLeft.latitude)/2, (visibleBounds.farLeft.longitude + visibleBounds.nearLeft.longitude)/2);
LatLng screenCenter = visibleBounds.latLngBounds.getCenter();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM