1

I have a MapControl and would like to know how many degrees are currently shown on the x and y axes.

First example: map landscape

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: map portrait

~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...

S. Matthews
  • 355
  • 2
  • 9
Tobias H
  • 71
  • 8

2 Answers2

4

You should use the MapControl's GetLocationFromOffset 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;
Clemens
  • 123,504
  • 12
  • 155
  • 268
-1

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;
Tobias H
  • 71
  • 8
  • 1
    This calculation is wrong, because it does not take the map projection into account (and of course uses the dubious magic value `409.5`). See my answer. – Clemens Jan 09 '16 at 11:17
  • I got the magic value while experimenting with the map. If i zoom out complete on a map with the size of 1000x1000 I can see 360deg longitude and 180deg latitude with a zoom level of about ~2.2 If i zoom out on a map with the size of 409.5x409.5 I also can see 360deg and 180deg with a zoom level of 1. So i figured out, that the zoom only refers to the center of 409.5x409.5 ^^ – Tobias H Jan 09 '16 at 16:16