简体   繁体   English

添加信息窗口-Google Maps API

[英]Adding infowindows - google maps API

So essentially I'm having a problem with adding info windows onto a map, in the google maps api. 因此,从本质上来说,我在使用Google Maps API将信息窗口添加到地图上时遇到了问题。

The markers work just fine so I'm not going to paste the code, but what doesn't work is the info window. 标记可以正常工作,因此我不会粘贴代码,但是信息窗口不起作用。 I can get the info window to load up something such as "hi", but when I want to access an object which I have declared outside the function, it says it is undefined. 我可以获取信息窗口来加载诸如“ hi”之类的东西,但是当我想访问在函数外部声明的对象时,它说它是未定义的。

google.maps.event.addListener(marker,'click',function(javascriptLocations){
    info.setContent(javascriptLocations[i]["name"]);
    info.open(worldMap,this);
});

I've declared javascriptLocations further up in the script here: 我在以下脚本中进一步声明了javascriptLocations:

<?php

$phpLocations = $getInfos->getLocations();
$jsonLocations = json_encode($phpLocations);
echo "javascriptLocations =".$jsonLocations.";";

?>

and it loads up just fine, it's simply when I want to access it inside the function it comes up with defined. 并且它可以很好地加载,只是当我想在它定义的函数中访问它时。 Thank you. 谢谢。

remove javascriptLocations as a parameter of the listener callback, or call it event or whatelse. 删除javascriptLocations作为侦听器回调的参数,或将其称为事件或其他。 In your code the javascriptLocations variable inside the function is the event object because is overwritten! 在您的代码中,函数内的javascriptLocations变量是事件对象,因为它被覆盖了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM