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.
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); }
Fabien, Thanks for recommending best practices around ZoomLevel. Here’s one more interesting tidbit about this property – to make Landmarks or Pedestrian Features visible, you have to specify a ZoomLevel of 16 or higher, as we mention here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207045(v=vs.105).aspx#BKMK_Pedestrianfeaturesandlandmarks.
That is very good to know too. Thanks a lot for pointing this out.