Javascript 我在google ap中设置gmaps.js时遇到了麻烦
我在谷歌地图中实现这个多输入引脚时遇到了一些麻烦 错误“无法调用方法“setContextMenu”未定义 有人知道我要怎么修吗Javascript 我在google ap中设置gmaps.js时遇到了麻烦,javascript,google-maps,Javascript,Google Maps,我在谷歌地图中实现这个多输入引脚时遇到了一些麻烦 错误“无法调用方法“setContextMenu”未定义 有人知道我要怎么修吗 var map; function initialize() { var mapOptions = { zoom: 15, center: new google.maps.LatLng(10.2833, 123.9000) }; map.setContextMenu({
var map;
function initialize() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(10.2833, 123.9000)
};
map.setContextMenu({
control: 'map',
options: [{
title: 'Add marker',
name: 'add_marker',
action: function(e) {
this.addMarker({
lat: e.latLng.lat(),
lng: e.latLng.lng(),
title: 'New marker'
});
}
}, {
title: 'Center here',
name: 'center_here',
action: function(e) {
this.setCenter(e.latLng.lat(), e.latLng.lng());
}
}]
});
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
var映射;
函数初始化(){
变量映射选项={
缩放:15,
中心:新google.maps.LatLng(10.2833123.9000)
};
map.setContextMenu({
控件:“映射”,
选项:[{
标题:“添加标记”,
名称:“添加标记”,
行动:职能(e){
这是addMarker({
lat:e.latLng.lat(),
lng:e.latLng.lng(),
标题:“新标记”
});
}
}, {
标题:'此处居中',
名称:'center_here',
行动:职能(e){
this.setCenter(e.latLng.lat(),e.latLng.lng());
}
}]
});
map=new google.maps.map(document.getElementById('map-canvas'),
地图选项);
}
google.maps.event.addDomListener(窗口“加载”,初始化);
在使用地图之前,您需要初始化地图。将此调用下移到初始化地图的行下方map.setContextMenu
map=new google.maps.map(
//first initialize the map
map = new google.maps.Map( //...
//now it is safe to use
map.setContextMenu({