how to find distance between two markers in openlayers?

Go To StackoverFlow.com

1

Hi i want to know how to find the distance between two markers in openlayers.

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

}

pleae help me...

2012-04-03 19:43
by Ramesh Kotha


4

Create points from your LonLat and call distanceTo method from 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

2012-04-04 08:48
by tonio