Suzan Cioc
Suzan Cioc

Reputation: 30107

Why does esri.geometry.getLength work wrong?

The function http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#namespace_geometry/esri.geometry.getLength should calculate distances between points.

When I am trying to calculate distance between points having 100 meters between them

p1=new esri.geometry.Point(3997030.6690969253, 7444299.320646087, new esri.SpatialReference({ wkid: 102113 }));
Object
p2=new esri.geometry.Point(3996951.455397143, 7444142.154020177, new esri.SpatialReference({ wkid: 102113 }));
Object
esri.geometry.getLength(p1, p2)
176.00045037719127

I am getting 176 which is wrong. Projection is Web Mercator (WKID 102113).

Upvotes: 2

Views: 682

Answers (1)

Gurduloo
Gurduloo

Reputation: 151

It looks like it's just calculating the simple euclidean map distance between the two points (3997030,7444299) and (3996951, 7444142).

a^2 + b^2 = c^2 
where a = (3997031 - 3996951) and b = (7444299 - 7444142)
c = 176

So 176 is the map distance, what you want is the real world ground distance. You'll probably have to use a GeometryService to accomplish this, I don't think the Javascript can do it on it's own. Here's ESRI's sample of it: https://developers.arcgis.com/javascript/jssamples/util_distance.html

Upvotes: 1

Related Questions