![]() In the Google Maps API, zoom is an integer somewhere between 1 (zoomed out as far as possible) and 20 (zoomed in as far as possible), so let’s round down to make sure the zoom level is big enough to capture the entirety of our area: zoom = Math.floor(Math.log2(156543.03392m/px * s(latitude * Math.PI / 180) * pixels / meters)) We just need to transform the equation so we’re solving for zoom. So, how do we zoom to the right scale while accounting this distortion? A tenacious search of Google Groups forums eventually yields this answer from a Google employee: meters/px = 156543.03392 * s(latitude * Math.PI / 180) / Math.pow(2, zoom) In other words, all else being equal, our little 500px map will show a different square footage depending on what latitude we’re centered on. The Mercator projection, which Google Maps uses, becomes more and more distorted the farther you travel from the equator. ![]() ![]() It seems like a simple enough problem, but there’s one complication: we’re trying to display a round object on a flat surface.
0 Comments
Leave a Reply. |