我有以下脚本使用点数的KML文件在Google地图上绘制点:
function initialize() {
var myLatlng = new google.maps.LatLng(49.496675,-102.65625);
var mapOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var mcOptions = {gridSize: 50, maxZoom: 15};
markers = [];
markerclusterer = new MarkerClusterer(map, [], mcOptions);
var infoWindow = new google.maps.InfoWindow({maxWidth:800});
var myParser = new geoXML3.parser({
map: map, singleInfoWindow:true,
createMarker:function(placemark){
//Constructing marker for each Placemark node, and then add it to the markclustere
var point = new google.maps.LatLng(placemark.point.lat, placemark.point.lng);
var marker = new google.maps.Marker({position:point});
markerclusterer.addMarker(marker);
google.maps.event.addListener(marker, "click", function(){
var marker_lat = marker.getPosition().lat();
var marker_lng = marker.getPosition().lng();
infoWindow.close();
infoWindow.setOptions({maxWidth:800});
content = "<strong>" + placemark.name + "</strong><br>" + placemark.description;
infoWindow.setContent(content);
infoWindow.open(map, marker);
});
markerclusterer.addMarker(marker);
}
});
myParser.parse('/staff/people/index.kml') ;
}
google.maps.event.addDomListener(window, 'load', initialize);
我想知道如何计算它绘制的点数,以便我可以更新div
。我知道如何更新div
,只是不知道如何计算。
任何助理都将不胜感激。
谢谢!
答案 0 :(得分:0)
.markers数组或.placemarks数组的长度将为您提供标记的数量(如果所有地标都是标记)。
myParser.docs[0].markers.length
或
myParser.docs[0].placemarks.length