即时通讯使用谷歌地图javascript api。在api中调用initialize方法的加载,但我一直得到“未捕获的SyntaxError:意外的令牌”错误但无法找到源为什么我得到这个错误。
请帮助。提前致谢
<script type='text/javascript'>
function initialize() {
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(-25.363882,131.044922)
};
var map = new google.maps.Map(document.getElementById('geochart-view-wrapper'),
mapOptions);
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
title: 'Click to zoom'
});
google.maps.event.addListener(map, 'center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});
google.maps.event.addListener(marker, 'click', function() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
google.maps.event.addDomListener(window,'load',initialize);
</script> `
答案 0 :(得分:0)
我通过JSHint运行脚本:
function initialize() {
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(-25.363882, 131.044922)
};
var map = new google.maps.Map(document.getElementById('geochart-view-wrapper'), mapOptions);
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
title: 'Click to zoom'
});
google.maps.event.addListener(map, 'center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
google.maps.event.addListener(marker, 'click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
google.maps.event.addDomListener(window, 'load', initialize);
现在这种语法没有错误。我的猜测是那条线
var map = new google.maps.Map(document.getElementById('geochart-view-wrapper'),
mapOptions);
造成了它。
顺便说一下,格式化代码可以更容易地识别逻辑错误,语法错误,关闭错误等。