如何找到openlayers中两个标记之间的距离?

时间:2012-04-03 19:43:04

标签: map openlayers

您好我想知道如何在开放层中找到两个标记之间的距离。

var distance = distanceBetweenMarkers(latLon1, latLon2){
//code to find the distance between latLon1, latLon2

}

请帮助我...

1 个答案:

答案 0 :(得分:4)

LonLat创建积分并从distanceTo调用Geometry.Point方法[1]。

p1 = new OpenLayers.Geometry.Point(latLon1.lon,latLon1.lat);
p2 = new OpenLayers.Geometry.Point(latLon2.lon,latLon2.lat);
len = p1.distanceTo(p2);

1 - http://dev.openlayers.org/docs/files/OpenLayers/Geometry/Point-js.html#OpenLayers.Geometry.Point.distanceTo