Does anyone have a solution for calculating the Latitude and Longitude corners of a view based on heading?
I have a function that calculates the LatLng corners of a view if heading is 0. But I wish to find a way to calculate the corners based on a new heading, if the user spins the map for example.
The code I have now that does this with Heading = 0 is this.
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;
}