Why getProjection () does not work in V3

According to the API ref, the map object must have a getProjection method:
http://code.google.com/apis/maps/documentation/v3/reference.html#Map

When loading a map in this example, it should warn the point x, y, but instead throws the value as undefined. This is the code example below called onload.

function initialize() { var mapOptions = { zoom: 8, center: new google.maps.LatLng(-34.397, 150.644), mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); alert("projection:"+map.getProjection()); } 
+7
source share
1 answer

It is not available until the card completes initialization. You must wait for the projection_changed event before accessing it.

 function initialize() { var mapOptions = { zoom: 8, center: new google.maps.LatLng(-34.397, 150.644), mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); google.maps.event.addListenerOnce(map,"projection_changed", function() { alert("projection:"+map.getProjection()); }); } 
+36
source

All Articles