Windows Phone Map control and ZoomLevel limits

ZoomLevel
The Oscars are over, I was playing with my application Earthquakes for Windows Phone and I noticed a bug in the map control. The problem is very simple, but I’d like to share it here with you Windows Phone developers so you don’t make the same mistake.
Like a lot of application that use the Map control, I have two buttons in the ApplicationBar that allow me to zoom in and zoom out.

ZoomLevelActions

So, when you use the Map control for Windows Phone 7 or Windows Phone 8, you can use the property ZoomLevel to zoom in or zoom out. On the click of the button I was simply increasing or decreasing the value without doing any control. I know that’s bad… Apparently, there is a limit for the zoom level that can be apply to the Map. Which is 1 to 19 for Windows Phone 7 and 1 to 20 for Windows Phone 8.

For Windows Phone 7 you can use the following code to change the ZoomLevel property:

private void BtZoomMore(object sender, EventArgs e)
{
   map.ZoomLevel = Math.Min(map.ZoomLevel + 1, 19);
}

private void BtZoomLess(object sender, EventArgs e)
{
   map.ZoomLevel = Math.Max(map.ZoomLevel - 1, 1);
}

And for Windows Phone 8:

private void BtZoomMore(object sender, EventArgs e)
{
   Map.ZoomLevel = Math.Min(Map.ZoomLevel + 1, 20);
}

private void BtZoomLess(object sender, EventArgs e)
{
   Map.ZoomLevel = Math.Max(Map.ZoomLevel - 1, 1);
}

3 thoughts on “Windows Phone Map control and ZoomLevel limits

Comments are closed.