I am wanting to calculate the zoom level for a given lat/long area. I am using the OSM/GE slippy map "standard" tile system.
The post below answers my question but requires the viewing screen resolution and then it projects the lat/long bounding box using the mercator projection.
And the answer in this post says "it would be cleaner to define in meters"
I dont understand why I would need to use the viewing resolution or bother to project the coordinates. Since I already know with the OSM/GE slippy map "standard" a single tile at level 0 covers 360 degrees in width(longitude). Each subsequent zoom level halves the previous longitude width:
at zoom level 0, a tile is the full width of the earth 360 degrees zoom level 1 = 2 a tile is 180 degrees zoom level 2 = 4 a tile is 90 degrees zoom level 3 = 8 a tile is 45 degrees zoom level 4 = 16 a tile is 22.5 degrees zoom level n = 2**(zoom level) a tile is 360 / 2**(zoom level) width in longitude
So for me to calculate the zoom level that would fit in a lat/long bounding box, I would just take the deltas of the bounding box and solve for the zoom level.
My calculation for zoom level is simply (in c#):
var deltaLat = boundingBox.MaxLat - boundingBox.MinLat; var deltaLong = boundingBox.MaxLong - boundingBox.MinLong; var zoomLevelWidth = (int)Math.Floor(Math.Log(360.0d / deltaLong) / Math.Log(2)); var zoomLevelHeight = (int)Math.Floor(Math.Log(170.0 / deltaLat) / Math.Log(2));
What am I missing? Why is this not the answer?