Skip to content

Instantly share code, notes, and snippets.

@panzi
Last active February 15, 2017 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save panzi/6694200 to your computer and use it in GitHub Desktop.
Save panzi/6694200 to your computer and use it in GitHub Desktop.
The new Google Maps seems to use a diameter instead of a zoom value. You can use this function to get the old zoom value from the diameter. I tested it with the given list of values.
function diameterToZoom (diameter) {
var zoom = Math.floor(19 - Math.log(diameter / 1000) / Math.LN2);
return zoom < 0 ? 0 : zoom > 20 ? 20 : zoom;
}
// tested with these values:
// diameter = zoom
// 758 = 19
// 1515 = 18
// 3031 = 17
// 6061 = 16
// 12122 = 15
// 24242 = 14
// 48480 = 13
// 96955 = 12
// 193999 = 11
// 388357 = 10
// 777642 = 9
// 1530533 = 8
// 3067439 = 7
// 7107071 = 6
// 12407563 = 5
// 27301053 = 4
// 51957442 = 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment