我在地图中显示了我的位置,如下所示:
<script type="text/javascript" src="https://maps-api-ssl.google.com/maps/api/js?v=3&sensor=true"></script>
<script type="text/javascript">
var map;
var markers = new Array();
var infos = new Array();
jQuery(document).ready(function(){
var mapOptions = {
zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
{% for position in positions %}
var address = '{{ position.map_position }}';
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var content_html = '<div>';
content_html += '<label style="font-weight:bold;">country name : </label>{{ position.country.country_name }}<br/>';
content_html += '<label style="font-weight:bold;">city name : </label>{{ position.city.city_name }}<br/>';
{% if position.related > 1 %}
content_html += '<a style="color:black;" href="Mylink">My link</a>';
{% endif %}
if(jQuery.inArray('{{ position.map_position }}', markers) == -1){
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
icon: '{{position.icon}}',
position: results[0].geometry.location
});
markers.push('{{ position.map_position }}');
var infowindow = new google.maps.InfoWindow({
content: content_html
});
infos.push(infowindow);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
else {
var infowindow = infos[jQuery.inArray('{{ position.map_position }}', markers)];
infowindow.setContent(infowindow.getContent()+'<hr>'+content_html);
}
}
});
{% endfor %}
});
</script>
我在地图上显示了位置,但如果我有超过 2 个标记,我可以打开所有这些标记。我怎样才能同时打开一个信息公牛?(如果我打开一个信息公牛,所有其他信息都保持关闭)