我在Javascript数组中有77个纬度和经度点,我需要通过邻近聚类在一组中订购此数组,然后在8组中,我该怎么做?
http://jsfiddle.net/mn8v7d3L/2/
var markers = [
[-23.5505199,-46.63330939999997],
[-23.70076253,-46.45489123],
...
];
function initializeMaps() {
var myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false
};
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
var marker, i;
var bounds = new google.maps.LatLngBounds();
var j = 0;
for (i = 0; i < markers.length; i++) {
var pos = new google.maps.LatLng(markers[i][0], markers[i][1]);
bounds.extend(pos);
marker = new google.maps.Marker({
position: pos,
map: map,
icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2%7C"+hue
});
j++;
if(j==8){
j=0;
hue = (Math.floor(Math.random() * 99)) + '00'+(Math.floor(Math.random() * 99)) ;
}
}
map.fitBounds(bounds);
}
initializeMaps();