1

見出しに基づいてビューの緯度と経度のコーナーを計算するためのソリューションはありますか?

見出しが 0 の場合、ビューの LatLng コーナーを計算する関数があります。しかし、たとえばユーザーがマップを回転させた場合、新しい見出しに基づいてコーナーを計算する方法を見つけたいと思います。

Heading = 0 でこれを行うコードはこれです。

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

        /*
         * resolution m/px = 15653.04 m/px * Cos(LatInRad) / 2^zoomLevel
         * 111325 m/deg
         */

        double latInRad = Math.Cos(map.Center.Position.Latitude * Math.PI / 180);
        double lngInRad = Math.Cos(map.Center.Position.Longitude * Math.PI / 180);

        double degreePerPixel = (156543.04 * latInRad * lngInRad) / (111325 * Math.Pow(2, map.ZoomLevel));

        double mHalfWidthInDegrees = map.ActualWidth * degreePerPixel / 0.89;
        double mHalfHeightInDegrees = map.ActualHeight * degreePerPixel / 1.65;

        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
            });
      return mBounds;
 }
4

2 に答える 2

2

可視マップ エリアの境界ボックスを取得する最も簡単な解決策は、マップ コントロールから値を直接取得することです。

Microsoft による組み込みの Map コントロールの場合、コントロールに対する相対値を取得し、その時点での地理的位置を返すMapControl.GetLocationFromOffsetメソッドがあります。Point

mapControl.GetLocationFromOffset(
   new Point(0, 0),
   out upperLeftGeoPoint
);
mapControl.GetLocationFromOffset (
   new Point( mapControl.ActualWidth, 0 ), 
   out upperRightGeoPoint
);
mapControl.GetLocationFromOffset (
   new Point( 0, mapControl.ActualHeight ), 
   out bottomLeftGeoPoint
);
mapControl.GetLocationFromOffset (
   new Point( mapControl.ActualWidth, mapControl.ActualHeight ), 
   out bottomRightGeoPoint
);

ポイントがマップ コントロールの範囲外にある場合、メソッドは例外をスローすることに注意してください。

あなたの場合、マップが回転しているため、四隅すべての値を取得する必要があります。

この方法の詳細については、MSDNを参照してください。

サード パーティの XAML マップ コントロールを使用している場合は、同等のViewportPointToLocation方法があります。

var northWestCorner = mapControl.ViewportPointToLocation( 
   new Point( 0, 0 )
);
var southEastCorner = mapControl.ViewportPointToLocation(
   new Point( mapControl.ActualWidth, mapControl.ActualHeight )
);
//analogous for north east, south west
于 2016-08-02T06:34:42.457 に答える
0

It looks like you are trying to calculate the bounding box of the map. Using degree per pixel won't work as this value changes with the latitude value. Instead take a look at the solution here on how to calculate the bounding box of a map in WP8.1 (this basis to the Win10 map control) Get view bounds of a Map

于 2016-08-02T00:41:39.360 に答える