In my web application, I have coordinate bounds that I'd like to modify to simulate "zooming in" on google maps. It seems that zooming back and forth with google maps simply doubles or halves each side of the bounding box. So my function to do this on the server looks like this:
private static decimal[] ZoomIn(decimal latMax, decimal lngMin, decimal latMin, decimal lngMax)
{
decimal lngAdjustment = (lngMax - lngMin) * .25m;
decimal latAdjustment = (latMax - latMin) * .25m;
return new[]
{
// North
latMax - latAdjustment,
// West
lngMin + lngAdjustment,
// South
latMin + latAdjustment,
// East
lngMax - lngAdjustment
};
}
The problem with this approach is the latAdjustment that I'm doing. When compared to an actual zoom using the google maps control, this ends up being fairly accurate when zoomed in to city level. However, it is less accurate the further the view is zoomed out. I assume this is due to the Mercator projection of the earth that google maps uses. Is anyone aware of a better formula or method to use to simulate a "zoom"?
Update: My issue has more to do with not knowing the correct formula than google maps. Let me illustrate using some sample numbers.
Take Chicago, centered at 41.8563226156679,-87.7339862646484
And a bounding box surrounding that point:
- West: -87.984955197753800
- East: -87.483017331542900
- South: 41.546931599561100
- North: 42.164224124684300
By observing the behavior of google maps, this bounding box zoomed in one level will be: - West: -87.859470731201100 - East: -87.608501798095600 - South: 41.701813184067600 - North: 42.010459667660800
(center is kept the same, there is no variance due to mouse movement, etc. I just used the manual zoom button, not the mouse)
Using my formula above, longitude will values will come out correct. Example:
west = west + (west - east) * .25 -87.984955197753800 + ((-87.483017331542900 - -87.984955197753800) * .25) = -87.859470731201075
However, the same formula will not work when dealing with latitude. It is near the correct values, but off by just enough that the map shifts noticeably. This effect is worse with larger bounding boxes and/or when the latitude is further from the equator. I assume this is due to the mercator projection of the earth. Trig class was a long time ago for me, and at this point I'm unable to find a suitable formula for zoom latitude for this situation.
latAdjustmentinaccurate? - bcdan