集群器 谷歌地图
我知道markerClusterer能够处理谷歌地图上的大量标记。 通过参考这个示例代码,如下所示
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="../src/data.json"></script>
<script type="text/javascript">
var script = '<script type="text/javascript" src="../src/markerclusterer';
if (document.location.search.indexOf('compiled') !== -1) {
script += '_compiled';
}
script += '.js"><' + '/script>';
document.write(script);
</script>
<script type="text/javascript">
function initialize() {
var center = new google.maps.LatLng(37.4419, -122.1419);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
for (var i = 0; i < 100; i++) {
var dataPhoto = data.photos[i];
var latLng = new google.maps.LatLng(dataPhoto.latitude,
dataPhoto.longitude);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
第一个问题,为什么这个示例 infowindow 无法工作?
其次,如果我有这样的数组:
[-6.358851,106.889359] => Array
(
[0] => stdClass Object
(
[name] => C
)
)
[-6.154060,106.854080] => Array
(
[0] => stdClass Object
(
[name] => A
)
[1] => stdClass Object
(
[name] => B
)
)
我可以像那些具有相同纬度和经度的数组一样,将信息堆叠在一个信息窗口中吗?我知道可能是这样。我只是想知道该怎么做。 json数据格式如何才能在地图上获得正确的输出?
希望这里的任何人都可以帮助我。提前致谢。
I know markerClusterer able to handling large amounts markers on google map.
By referring this example code as below shown
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="../src/data.json"></script>
<script type="text/javascript">
var script = '<script type="text/javascript" src="../src/markerclusterer';
if (document.location.search.indexOf('compiled') !== -1) {
script += '_compiled';
}
script += '.js"><' + '/script>';
document.write(script);
</script>
<script type="text/javascript">
function initialize() {
var center = new google.maps.LatLng(37.4419, -122.1419);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
for (var i = 0; i < 100; i++) {
var dataPhoto = data.photos[i];
var latLng = new google.maps.LatLng(dataPhoto.latitude,
dataPhoto.longitude);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
First question, why this example infowindow cannot work?
Second if I have such array like this:
[-6.358851,106.889359] => Array
(
[0] => stdClass Object
(
[name] => C
)
)
[-6.154060,106.854080] => Array
(
[0] => stdClass Object
(
[name] => A
)
[1] => stdClass Object
(
[name] => B
)
)
Can I do like those have the same lat and lon, stack the information within one infowindow? I know it could be. I just wondering how to do it. And how does the json data format to get the right output on map?
Hope anyone here can help me. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个问题;什么信息窗口?您的代码中没有信息窗口。您需要做的是在循环内,为每个标记创建一个 infowindow 变量,设置其内容,并为该标记创建一个事件侦听器。
First question; what infowindow? Your code has no infowindow in it. What you need to do is inside your loop, create an infowindow variable for each marker, set its content, and create an event listener for that marker.