Take the 2-minute tour ×

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 }));
p2=new esri.geometry.Point(3996951.455397143, 7444142.154020177, new esri.SpatialReference({ wkid: 102113 }));
esri.geometry.getLength(p1, p2)

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


@Krystian found that getLength uses just Pythagoras theorem to calculate length. So it gives length in projection meters. How to obtain distance in real meters?

share|improve this question
try use geoprocessor tool to check your distance (esri.tasks.GeometryService.lengths() ), maybe you want have geodetic distance between those points, and getLength method is counting straight length between points (it's just my blind shot) –  Krystian Jan 31 '13 at 12:47
It's 100 meters. Difference between two methods should not be 76 meters. This is most probably because getLength does not understand projection. Or may be I don't understand something. –  Suzan Cioc Jan 31 '13 at 12:59
add comment

2 Answers

up vote 4 down vote accepted

Web Mercator Auxiliary Sphere is WKID 102100


var polyline = {
    "paths":[[[3997030.6690969253, 7444299.320646087], [3996951.455397143, 7444142.154020177]]],
polyline = new esri.geometry.Polyline(polyline);
polyline = esri.geometry.webMercatorToGeographic(polyline);
console.log(esri.geometry.geodesicLengths([polyline], esri.Units.METERS));
//output 99.93917832865446

6.1 cm short, good enough for govment work?

share|improve this answer
yeah, yours answer is faster than main. but we thought about same thing! :) –  Krystian Jan 31 '13 at 23:18
add comment

I just checked it.

esri.geometry.getLength(p1, p2) is counting distance like this:

length = sqrt((p2_X - p1_X)^2 + (p2_Y - P1_Y)^2)

so it is distance between two points in straight line. If you want to count distance between two points on geodetic line you should use geometry service as in this example

share|improve this answer
Algorithm looks wrong. But it's problem is not that it takes straight line, but that it ignores projection. –  Suzan Cioc Jan 31 '13 at 15:31
You don't really need the geometry service. Although, it would be an interesting to test the difference between the javascript API and the geometry service. –  awesomo Jan 31 '13 at 19:08
add comment

Your Answer


