98

How do I find the current zoom level when loading or clicking a Google map?

AlvaroSantisteban
  • 5,256
  • 4
  • 41
  • 62
K6t
  • 1,821
  • 1
  • 13
  • 21
  • 11
    um, [`Map.getZoom()`](http://code.google.com/apis/maps/documentation/javascript/reference.html)? – Pekka Jun 17 '11 at 12:28

4 Answers4

170

If you have a map object like this:

var mapObject = new google.maps.Map(document.getElementById("map"), _mapOptions);

use

mapObject.getZoom();
bert
  • 7,566
  • 3
  • 31
  • 47
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
20

Use this code:

float zoomlevel = mMap.getCameraPosition().zoom;
Ingo
  • 5,239
  • 1
  • 30
  • 24
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Rosário Pereira Fernandes Jan 22 '18 at 01:43
12

If you need to get zoom on change

google.maps.event.addListener(map, 'zoom_changed', function() {
    var zoom = map.getZoom();
    console.log(zoom);
});
Endrit Vitija
  • 121
  • 1
  • 7
3

I got it using:

console.log(this.map.zoom);

I'm using agm-angular-google-maps

html:

<agm-map (mapReady)="onMapReady($event)">

TS:

onMapReady(map) {
 this.map = map;
}