is a good idea for solving my problem.
Now, the problem is: how do I calculate "double" the zoom level?
EDIT
Meaning:
the map is looking at a square 2x2 km, I want to zoom out to look at a 4x4 km square.
Doing newZoom=oldZoom*2 does not work :-(((
is a good idea for solving my problem.
Now, the problem is: how do I calculate "double" the zoom level?
EDIT
Meaning:
the map is looking at a square 2x2 km, I want to zoom out to look at a 4x4 km square.
Doing newZoom=oldZoom*2 does not work :-(((
Each increment of the zoom level doubles the scale. To zoom out by a factor of two, add one to the zoom level.
newZoom=oldZoom-1; World coordinates reflect absolute locations on a given projection, but we need to translate these into pixel coordinates to determine the "pixel" offset at a given zoom level. These pixel coordinates are calculated using the following formula:
pixelCoordinate = worldCoordinate * 2 zoomLevel
From the above equation, note that each increasing zoom level is twice as large in both the x and y directions. Therefore, each higher zoom level contains four times as much resolution as the preceding level. For example, at zoom level 1, the map consists of 4 256x256 pixels tiles, resulting in a pixel space from 512x512. At zoom level 19, each x and y pixel on the map can be referenced using a value between 0 and 256 * 219
Use the SetZoom() method:
map.setZoom(oldZoom * 2); Also with GetZoom():
map.setZoom(map.GetZoom() * 2); The maximum zoom level is 19 in general. 0 being the most zoomed out.
It is worth noting that is not always possible to zoom to 19 on every part of the map, here is more info about it: https://developers.google.com/maps/documentation/javascript/maxzoom
And the parts where you can zoom further: http://www.wolfpil.de/v3/deep-zoom.html
Although I'm not still not sure what you would like to achieve but I made this. It seems silly a bit, but I really don't know what else could it be.
Code snippet:
google.maps.event.addDomListener(zoomInButton, 'click', function () { if (newZoom <= 19) { oldZoom = newZoom; newZoom = oldZoom * 2; //maptOptions.zoom is the initial oldZoom alert("New zoom is: " + newZoom); alert("Old zoom is: " + oldZoom); map.setZoom(newZoom); } else { alert("you have reached the maximum"); } }); // Setup the click event listener - zoomOut google.maps.event.addDomListener(zoomOutButton, 'click', function () { if (newZoom > 1) { oldZoom = newZoom; newZoom = parseInt(oldZoom / 2); alert("New zoom is: " + newZoom); alert("Old zoom is: " + oldZoom); map.setZoom(newZoom); } else { alert("you have reached the minimum"); } }); fiddle URL: http://jsfiddle.net/eugensunic/jptLfhc8/121/