【发布时间】:2019-05-28 19:07:31
【问题描述】:
所以我正在使用谷歌地图 api 的信息框插件/插件,我可以让标记出现,但是当我点击它时没有任何反应。我的代码主要来自示例,但由于某种原因它没有按应有的方式弹出。我是否需要以尚未导入的方式导入它?(因为当我声明一个新的信息框时,信息框没有突出显示)。我该怎么办?
信息框插件:https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/infobox/src/infobox.js
我的 jsfiddle:https://jsfiddle.net/kaidemarco/06wpx75j/49/
*我也尝试使用显示您的代码进行格式化,但效果不佳。
function initMap() {
var Jays = {lat: 39.280126,lng: -74.574394};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
center: Jays
});
var marker = new google.maps.Marker({
map: map,
draggable: false,
position: Jays,
visible: true
});
var boxText = document.createElement("div");
boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;";
boxText.innerHTML = "City Hall, Sechelt<br>British Columbia<br>Canada";
var myOptions = {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-140, 0)
,zIndex: null
,boxStyle: {
background: "url('tipbox.gif') no-repeat"
,opacity: 0.75
,width: "280px"
}
,closeBoxMargin: "10px 2px 2px 2px"
,closeBoxURL: "https://www.google.com/intl/en_us/mapfiles/close.gif"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
google.maps.event.addListener(marker, "click", function (e) {
ib.open(map, this);
});
var ib = new InfoBox(myOptions);
ib.open(map, marker);
}
【问题讨论】:
-
你的 jsfiddle 不起作用。您正在直接链接到不可执行的 github 存储库:
Refused to execute script from 'https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/infobox/src/infobox.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.和Uncaught (in promise) ReferenceError: InfoBox is not defined
标签: html google-maps google-maps-api-3 maps infobox