[英]Uncaught TypeError: google.maps.infoWindow is not a constructor
While trying to implement a google maps marker I've got this error and just couldn't get rid of it.在尝试实现谷歌地图标记时,我遇到了这个错误并且无法摆脱它。
The error:错误:
Uncaught TypeError: google.maps.infoWindow is not a constructor
未捕获的类型错误:google.maps.infoWindow 不是构造函数
at addMarker (functions.js:25)
在 addMarker (functions.js:25)
at window.onload (functions.js:36)在 window.onload (functions.js:36)
My code:我的代码:
window.onload = function(){
var map;
function initialize(){
var mapProp = {
center: new google.maps.LatLng(-27.648598,-48.577423),
scrollwheel: false,
zoom: 14,
mapTypeId:google.maps.MapTypeId.SATELLITE
}
map = new google.maps.Map(document.getElementById("mapa"),mapProp);
}
function addMarker(lat,long,icon,content){
var latLng = {'lat':lat,'lng':long};
var marker = new google.maps.Marker({
position:latLng,
map:map,
icon:icon
});
var infoWindow = new google.maps.infoWindow({
content:content,
maxWidth:200,
pixelOffSet: new google.maps.Size(0,20)
});
infoWindow.open(map,marker);
}
initialize();
addMarker(-27.616637,-48.5923228,'','address');
}
You have a typo in your code.您的代码中有错字。 JavaScript is case sensitive,
InfoWindow
in the constructor should be capitalized; JavaScript区分大小写,构造函数中的
InfoWindow
要大写; google.maps.infoWindow
is not the same as google.maps.InfoWindow
google.maps.infoWindow
与google.maps.InfoWindow
不同
Working Code snippet:工作代码片段:
window.onload = function(){ var map; function initialize(){ var mapProp = { center: new google.maps.LatLng(-27.648598,-48.577423), scrollwheel: false, zoom: 14, mapTypeId:google.maps.MapTypeId.SATELLITE } map = new google.maps.Map(document.getElementById("mapa"),mapProp); } function addMarker(lat,long,icon,content){ var latLng = {'lat':lat,'lng':long}; var marker = new google.maps.Marker({ position:latLng, map:map, icon:icon }); var infoWindow = new google.maps.InfoWindow({ content:content, maxWidth:200, pixelOffSet: new google.maps.Size(0,20) }); infoWindow.open(map,marker); } initialize(); addMarker(-27.616637,-48.5923228,'','address'); }
html, body { height: 100%; width: 100%; padding: 0px; margin: 0px; } #mapa { height: 100%; }
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script> <div id="mapa"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.