如何获得地图控件的边界



寻求在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-viewchanging-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;
    }

这个函数缺少的是在用户旋转地图时计算标题。有人有解决办法吗?

相关内容

  • 没有找到相关文章

最新更新