Google Maps Api v3 - getBounds未定义(Google Maps Api v3 - getBounds is undefined)
我从v2切换到v3 google maps api,并遇到
gMap.getBounds()
函数的问题。我需要在初始化之后获取我的地图的边界。
这是我的JavaScript代码:
var gMap; $(document).ready( function() { var latlng = new google.maps.LatLng(55.755327, 37.622166); var myOptions = { zoom: 12, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; gMap = new google.maps.Map(document.getElementById("GoogleMapControl"), myOptions); alert(gMap.getBounds()); } );
所以现在它提醒我,
gMap.getBounds()
是未定义的。我试图在点击事件中获取getBounds值,它对我来说可以正常工作,但是我无法在load map事件中获得相同的结果。
在Google Maps API v2中加载文档时,getBounds也可以正常工作,但在V3中失败。
你能帮我解决这个问题吗?
I'm switching from v2 to v3 google maps api and got a problem with
gMap.getBounds()
function.I need to get the bounds of my map after its initialization.
Here is my javascript code:
var gMap; $(document).ready( function() { var latlng = new google.maps.LatLng(55.755327, 37.622166); var myOptions = { zoom: 12, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; gMap = new google.maps.Map(document.getElementById("GoogleMapControl"), myOptions); alert(gMap.getBounds()); } );
So now it alerts me that
gMap.getBounds()
is undefined.I've tried to get getBounds values in click event and it works fine for me, but I cannot get the same results in load map event.
Also getBounds works fine while document is loading in Google Maps API v2, but it fails in V3.
Could you please help me to solve this problem?
原文:https://stackoverflow.com/questions/2832636
最满意答案
我认为这是因为
__FILE__
是一个解析时间常数,而__dir__
是一个函数,并返回File.dirname(File.realpath(__FILE__))
有关详细信息,请参阅此讨论
I think that is because
__FILE__
is a parse-time constant whereas__dir__
is a function and returnsFile.dirname(File.realpath(__FILE__))
For more details, see This discussion
相关问答
更多-
在类中使用__DIR__(usage of __DIR__ in a class)[2023-09-17]
你不能定义类字段dinamycally private $a = 5 + 4; // wont work, has to be evaluated private $a = 9; // works,because static value 解决方案: class abs{ private $path; public function __construct(){ $this->path = __DIR__ . DIRECTORY_SEPARATOR. 'moshe' . DIRECTOR ... -
代码中的多个问题共同导致问题 您将打开的FILE *存储在temp中,但检查kp。 我想那是因为你复制粘贴上面的支票。 可以通过更改变量轻松修复 您执行scanf设置之外的大小写操作。 正如@MOehm所建议的那样,将循环条件更改为s[i] 最后,您将在s中转换字符串,但在文件中保存k。 k永远不会被修改。 改变fprintf(temp, "%s", k); 到fprintf(temp, "%s", s); Multiple issues in your code which together cause ...
-
我认为这是因为__FILE__是一个解析时间常数,而__dir__是一个函数,并返回File.dirname(File.realpath(__FILE__)) 有关详细信息,请参阅此讨论 I think that is because __FILE__ is a parse-time constant whereas __dir__ is a function and returns File.dirname(File.realpath(__FILE__)) For more details, see Th ...
-
他们的结果是完全一样的 ; 所以没有区别。 例如,以下两行: var_dump(dirname(__FILE__)); var_dump(__DIR__); 会给出相同的输出: string '/home/squale/developpement/tests/temp' (length=37) 但是,至少有两个区别: __DIR__只存在于PHP> = 5.3 这就是为什么dirname(__FILE__)被更广泛地使用 __DIR__在编译时进行评估,而dirname(__FILE__)表示一个函数调 ...
-
如果你这样做 require(__DIR__ . '/file.php') 那么你需要具有完整路径名的文件。 如果另一个目录中的另一个文件需要执行此要求的文件,则此要求将始终有效。 另一方面,如果你 require('file.php') 然后,如果另一个目录中的另一个文件需要此require语句所在的文件,则此语句将失败。 这就是为什么通常包含__DIR__好习惯。 If you do require(__DIR__ . '/file.php') then you are requiring the ...
-
PHP basename(__DIR__)在某些服务器上返回_DIR_(PHP basename( __DIR__ ) is returning _DIR_ on some servers)[2022-11-26]
__DIR__是在PHP 5.3中引入的。 仔细检查你的PHP版本。 参考: http : //php.net/manual/en/language.constants.predefined.php __DIR__ is introduced in PHP 5.3 . Double check your PHP version . Reference: http://php.net/manual/en/language.constants.predefined.php -
当你使用define('Head', __DIR__ .'/views/head.php'); 你已经在定义中硬编码了斜杠。 但是默认情况下,Windows使用\作为默认目录分隔符,因此__DIR__将在Windows中的路径中使用\ (可以使用/作为替代,但它应该不是问题)。 如果希望它们保持一致,可以执行以下操作: define('Head', __DIR__ .DIRECTORY_SEPARATOR ."views".DIRECTORY_SEPARATOR ."head.php"); When yo ...
-
我推荐dirname(__DIR__) : 它是便携式的(适用于不允许a/b/../c Windows) 它是可读的 I recommend dirname(__DIR__): it's portable (works on Windows where a/b/../c is not allowed) it's readable
-
为什么需要限制模块列出的内容? dir()大多是调试工具。 通常会在对象的类型上查找魔术方法,因此对于实例, dir()查找type(instance).__dir__ 。 您的功能不在module类型上,而是在模块实例上。 但是,您无法扩展module类型,因此无法为模块提供自定义__dir__方法。 如果你想限制你from yourmodule import *导入的内容,那么请改用__all__ ; 它应该是一个列表,而不是一个函数。 有关详细信息,请参阅import语句文档 。 Why do you ...
-
__DIR__使用反射(__DIR__ VS using Reflection)[2024-02-21]
__DIR__返回被调用文件的目录。 Symphony2代码返回类的定义目录,这很可能是一个不同的文件。 __DIR__ returns the directory of the file where it is called. The Symphony2 code returns the directory of where the class is defined, which most likely is a different file.