为什么getProjection()在V3中不起作用 [英] Why getProjection() is not working in V3

查看:237
本文介绍了为什么getProjection()在V3中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据API ref,地图对象应该有一个getProjection
方法:

http://code.google.com/apis/maps/documentation/v3/reference.html#Map

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

在这个例子中加载映射时,
应该提醒x,y点,但是
会将该值作为未定义值来引发。

While loading the map in this example should alert the x,y point, but instead throws the value as undefined. This is the below sample code called in 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());
}


推荐答案

地图完成初始化。您必须在访问它之前等待projection_changed事件。

It isn't available until the map is finished initializing. You have to wait on 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());
 });
}

这篇关于为什么getProjection()在V3中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆