0
我有一个谷歌地图,我得到所有关闭地点(lat,lng)的标记。 这一点是确定的。排序计算区域
现在我想排序这些标记,就像在SQL中一样,我们可以做一个“按距离ASC排序”的例子。
我在javascript中看到有一个方法调用sort(),它可以对一些数字进行排序asc或desc例如。
标记有一些信息:姓名,职务,性别,城市,邮编...
我的代码:
var nbMeters = 50000;
for (var i = 0; i < markers.length; i++) {
var myMarker = markers[i];
coord2 = new google.maps.LatLng(myMarker.lat, myMarker.lng);
var distance = google.maps.geometry.spherical.computeDistanceBetween(coords, coords2);
if(distance <= nbMeters) {
alert(myMarker.name);
//OK my marker is close the variable coords, good !
//But how to know which marker is the closer, which is the second, the third ... and the less closer ??
}
}
你有一个想法?