
Question:
I have a MapControl and would like to know how many degrees are currently shown on the x and y axes.
First example: <a href="https://i.stack.imgur.com/OiyKp.png" rel="nofollow"><img alt="map landscape" class="b-lazy" data-src="https://i.stack.imgur.com/OiyKp.png" data-original="https://i.stack.imgur.com/OiyKp.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>
360 degrees are shown on the x axis (longitude)
~90 degrees are shown on the y axis (latitude)
(The zoom level is 3.2 and it's max zoomed out)
Second example: <a href="https://i.stack.imgur.com/atwsH.png" rel="nofollow"><img alt="map portrait" class="b-lazy" data-src="https://i.stack.imgur.com/atwsH.png" data-original="https://i.stack.imgur.com/atwsH.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>
~220 degrees on the x axis (longitude)
180 degrees on the y axis (latitude)
(zoom level: 1.7; max zoomed out)
I tried calculating the current degrees on the x axis using following code:
double dist = 360 * Math.Pow(0.5, macSurrounding.ZoomLevel - 1);
but it doesn't work, because the zoom level is just strange...
Answer1:You should use the MapControl's <a href="https://msdn.microsoft.com/de-de/library/windows/apps/windows.ui.xaml.controls.maps.mapcontrol.getlocationfromoffset.aspx" rel="nofollow">GetLocationFromOffset</a> method to calculate the geographic coordinates of the south-east and north-west corner points of the current map viewport. The width and height of the viewport would be the latitude and longitude differences of these points.
Geopoint northEast;
Geopoint southWest;
map.GetLocationFromOffset(new Point(map.ActualWidth, 0), out northEast);
map.GetLocationFromOffset(new Point(0, map.ActualHeight), out southWest);
var width = northEast.Position.Longitude - southWest.Position.Longitude;
var height = northEast.Position.Latitude - southWest.Position.Latitude;
Answer2:Got it:
Longitude:
360 * Math.Pow(0.5, mcMapControl.ZoomLevel - 1) * mcMapControl.ActualWidth / 409.5;
Latitude:
180 * Math.Pow(0.5, mcMapControl.ZoomLevel - 1) * mcMapControl.ActualHeight / 409.5;