【发布时间】:2015-01-16 08:19:40
【问题描述】:
我正在使用此代码创建一个谷歌地图,其中 3 个点隐藏在一个标记中,当单击一个标记时,这些点要么合并到一个标记中,要么打开为 3 个单独的点,但是地图没有出现任何人都可以检查我的代码并查看潜在问题吗?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>favorite cities</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
(function() {
window.onload = function(){
var options = {
zoom: 3,
center: new google.maps.LatLng(37.99, -93.77),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options);
var mgr = new MarkerManager(map);
var A = new google.maps.Marker({
position: new google.maps.LatLng(37.99, -93.77),
icon: 'img/cluster.png'
});
google.maps.event.addListener(A, 'click', function() {
map.setZoom(7);
map.setCenter(Kloof.getPosition());
});
var Cities = [A];
var Schools = [
//SChool1
new google.maps.Marker({position: new google.maps.LatLng(38.99, -93.97)}),
//School2
new google.maps.Marker({position: new google.maps.LatLng(37.89, -94.77)}),
//School3
new google.maps.Marker({position: new google.maps.LatLng(37.79, -95.77)})
];
google.maps.event.addListener(mgr, 'loaded', function() {
agr.addMarkers(Cities, 11, 6);
agr.addMarkers(Schools, 6);
agr.refresh
});
};
})();
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
【问题讨论】:
-
position: new google.maps.LatLng()后缺少参数和逗号。Area是无效的数组。修复语法错误和参数问题并回复我们。 -
请提供Minimal, Complete, Tested and Readable example。如果您的“真实”数据受到“限制”,请提供允许重现问题的测试数据。
-
@PHPglue 仍然没有地图出现
-
@geocodezip 感谢您提供的提示,它现在使用示例数据进行更新
-
我在你的代码 sn-p 上得到
Uncaught SyntaxError: Unexpected identifier(就像 PHPglue...),修复它(如建议的那样)在这一行Uncaught SyntaxError: Unexpected token ;上提供更多语法错误var Cities = [A;
标签: javascript google-maps google-maps-api-3 google-maps-markers markerclusterer