我已经尝试了几个小时,也提到了这个论坛上的一个帖子,但失败了。我有大量的标记,地图上最多有 1000 个标记。当我尝试移动地图的位置时,它会减慢我的地图速度。所以我需要设置要在地图上显示的标记间隔。当有超过 300 个标记时,假设间隔为 10。我怎样才能做到这一点?下面是我的代码:
var trace_markers= [];
var pins = [];
var pin;
function Trace_Pin(Lat, Long, immat, type, site, vitesse, date){
pin = {
latitude: document.getElementById('Lat'),
longitude: document.getElementById('Long'),
immat: document.getElementById('immat'),
date: document.getElementById('date'),
type: document.getElementById('type'),
site: document.getElementById('site'),
speed: document.getElementById('vitesse')
};
pins.push(pin);
ListPin();}
function ListPin()
{
var image_trace = new google.maps.MarkerImage('http://maps.google.com/mapfiles/kml/pal3/icon61.png',
new google.maps.Size(32, 32),
new google.maps.Point(0,0),
new google.maps.Point(16, 16));
if (pins.length > 200){
for ( var i=0; i< pins.length ;i+10){
var vehlatlng = new google.maps.LatLng(pins[i].latitude, pins[i].longitude) ;
var trace_marker = new google.maps.Marker({
map: map,
position: vehlatlng,
icon: image_trace });
trace_marker.tooltip_html = '<div class="tooltip">' + 'Date : ' + pins[i].date + '<br>' + 'Vitesse : ' + pins[i].vitesse + ' km/h' + '<br>' + '<\/div>';
trace_markers.push(trace_marker);
trace_marker.setMap(map);
Liste_Points.push(trace_marker.getPosition());
TraceBounds.extend(trace_marker.position); }
}
if (pins.length < 200){
for ( var i=0;i< pins.length ;i++){
var vehlatlng = new google.maps.LatLng(pins[i].latitude, pins[i].longitude) ;
var trace_marker = new google.maps.Marker({
map: map,
position: vehlatlng,
icon: image_trace });
trace_marker.tooltip_html = '<div class="tooltip">' + 'Date : ' + pins[i].date + '<br>' + 'Vitesse : ' + pins[i].vitesse + ' km/h' + '<br>' + '<\/div>';
trace_markers.push(trace_marker);
trace_marker.setMap(map);
Liste_Points.push(trace_marker.getPosition());
TraceBounds.extend(trace_marker.position); }
}
// Evenement MouseOver
//-----------------------------------------------------
google.maps.event.addListener(map, 'mouseover', function() {
showTooltip(trace_marker);
});
}
// ------------------------------------------------------------------------------------
//**************************************************************************************
// On joint les points du parcours
//**************************************************************************************
// ------------------------------------------------------------------------------------
function Trace_Route() {
if (route) { route.setMap(null); }
if (Liste_Points.length > 1) {
route = new google.maps.Polyline({
path: Liste_Points,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2});
route.setMap(map);
}
}