簡體   English   中英

如何獲取地圖控件的邊界?

[英]How to get the bounds of a map control?

尋求幫助在 Windows Phone c# 上獲取地圖控件的邊界,如地圖頂部的緯度,地圖底部的經度(可見區域),與經度相同,但顯然是左/右。

我為菜鳥“給我答案”之類的問題道歉,但我完全不知道該怎么做。

代碼:

public LocationRectangle GetVisibleMapArea(Map mMap)
{
    GeoCoordinate mCenter = mMap.Center;
    Point pCenter = mMap.ConvertGeoCoordinateToViewportPoint(mCenter);
    GeoCoordinate topLeft = MapVieMode.ConvertViewportPointToGeoCoordinate(new Point(0, 0));
    GeoCoordinate bottomRight = MapVieMode.ConvertViewportPointToGeoCoordinate(new Point(MapVieMode.ActualWidth, MapVieMode.ActualHeight));

    if (topLeft != null && bottomRight != null)
    {
        Point pNW = new Point(pCenter.X - mMap.ActualWidth / 2, pCenter.Y - mMap.ActualHeight / 2);
        Point pSE = new Point(pCenter.X + mMap.ActualWidth / 2, pCenter.Y + mMap.ActualHeight / 2);
        if (pNW != null && pSE != null)
        {
            GeoCoordinate gcNW = mMap.ConvertViewportPointToGeoCoordinate(pNW);
            GeoCoordinate gcSE = mMap.ConvertViewportPointToGeoCoordinate(pSE);
            return new LocationRectangle(gcNW, gcSE);
        }
    }

    return null;
}

取自此處的示例: http : //code.msdn.microsoft.com/wpapps/Windows-Phone-8-Map-0ca7bd6c

我創建了一段代碼,用於在 UWP 中查找 mapControl 的視點。

原始來源位於https://social.msdn.microsoft.com/Forums/windowsapps/en-us/4e5398de-ec50-46df-84d5-087dcaa20924/wp8-map-viewchanged-and-viewchanged-events-extents?forum=wpdevelop

享受

    public GeoboundingBox GetBounds(MapControl map)
    {
        if(map.Center.Position.Latitude == 0) { return default(GeoboundingBox); }

        double degreePerPixel = (156543.04 * Math.Cos(map.Center.Position.Latitude * Math.PI / 180)) / (111325 * Math.Pow(2, map.ZoomLevel));

        double mHalfWidthInDegrees = map.ActualWidth * degreePerPixel / 0.9;
        double mHalfHeightInDegrees = map.ActualHeight * degreePerPixel / 1.7;

        double mNorth = map.Center.Position.Latitude + mHalfHeightInDegrees;
        double mWest = map.Center.Position.Longitude - mHalfWidthInDegrees;
        double mSouth = map.Center.Position.Latitude - mHalfHeightInDegrees;
        double mEast = map.Center.Position.Longitude + mHalfWidthInDegrees;

        GeoboundingBox mBounds = new GeoboundingBox(
            new BasicGeoposition()
            {
                Latitude = mNorth,
                Longitude = mWest
            },
            new BasicGeoposition()
            {
                Latitude = mSouth,
                Longitude = mEast
            });

        Debug.WriteLine("New Bounds: NW = " + mNorth + ":" + mWest + " SE = " + mSouth + ":" + mEast);

        return mBounds;
    }

如果用戶旋轉地圖,此函數缺少的是計算航向。 有人對此有解決方案嗎?

暫無
暫無

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

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