我试图在单击覆盖(自定义HTML标记)后打开信息框。谷歌地图信息框在自定义HTML标记
此地图显示了一个典型的标记和客户HTML标记。当我点击典型标记时,信息框将正确打开。当我单击自定义HTML标记时,信息框无法打开,并显示错误消息:TypeError: anchor.getPosition is not a function
。这与我传递给infobox.open()
的不正确参数有关。它需要一个标记,但是由于我点击覆盖图(自定义HTML标记),传递的参数不正确。
如何调整infobox.open()
函数,使其能够接受我的覆盖图作为参数?自定义HTML标记脚本
<!DOCTYPE html>
<html>
<style>
#map{
height: 600px;
width: 600px;
}
</style>
<body>
<div id="map"></div>
<script src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script src="https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<script src="....path/to/custom-html-markers-google-maps.js"></script>
<script>
var infobox = new InfoBox({
disableAutoPan: false,
maxWidth: 300,
pixelOffset: new google.maps.Size(-75, -70),
zIndex: null,
boxStyle: {width: '150px'},
infoBoxClearance: new google.maps.Size(15, 50)
});
function initialize() {
var loc = new google.maps.LatLng(-33.89, 151.26);
var locMarker = new google.maps.LatLng(-33.89, 151.23);
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: loc,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
//This works FINE.. It sets the marker and infobox listener
var marker = new google.maps.Marker({
map: map,
position: locMarker,
visible: true
});
google.maps.event.addListener(marker, 'click', function() {
infobox.setContent('<div style="background-color:yellow">This is<br>an infobox.</div>');
infobox.open(map, this);
});
//Overlay from: http://humaan.com/custom-html-markers-google-maps/
var overlay = new CustomMarker(loc, map, {marker_id: '123'});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
</html>
部分:
google.maps.event.addDomListener(div, "click", function(event) {
infobox.setContent('<div style="background-color:yellow">Hi there</div>');
infobox.open(map, this); //*******THIS IS THE PROBLEM********
google.maps.event.trigger(self, "click");
});
我的问题是infobox.open(map, this);
期待一个标志,我给它的“分区”。我怎样才能调整这个功能,以便它接受我的div?
完整的脚本:http://humaan.com/custom-html-markers-google-maps/
谢谢,修订被带入该函数的经纬度位置和地图变量。 – Bxx