I have an ArcGIS map created using the JavaScript API (version 3.23). I have coded it so I can add points by clicking on the map (I simply create a point object at the mapPoint of the mouse event on click). I can then get the distance between two points by using simple code like the following:

esri.geometry.getLength(p1, p2)

Which gives me a distance between the two points in map units. I can then use:


to determine how many meters are equivalent to 1 map unit, which in my case returns 1, indicating that 1 map unit is 1 meter, and therefore the result of getLength should be equivalent to meters.

Unfortunately, this does not appear to be the case. For example, if I place one point at the beginning of the on-screen scale, and a second point at the 2Km mark on the scale, I would expect getLength to return something around 2,000. However, in actuality it returns (in one test) 3,172. The results are similar if I use a feature of known size and place one point on either side of said feature - the distance calculated by getLength is significantly larger than the actual distance, by around 50%. This doesn't appear to be an issue with the getLength function either - looking at the x and y coordinates of the points indicates that the calculation is correct - in map units, the points are the distance apart indicated. Said distance simply doesn't appear to line up with the scale or features drawn on the map.

This appears to have something to do with being fairly far north (Alaska), as if I try the same test closer to the equator (Mexico), I get results much more in line with what appears on the map. So perhaps the features on the map, and the scale bar, are stretching as you go further north, but there is no indication of that in the mapUnits? If so, how can I determine this "stretch" factor?

What am I doing wrong, and how can I fix it?

  • Did you try projecting your polyline into geographic, then calling geodesicUtils.geodesicLengths ? – Kirk Kuykendall May 9 '19 at 18:16
  • @KirkKuykendall No, I did not. Actually I was not even aware of that particular function. I'll have to give it a try. – ibrewster May 9 '19 at 21:53

The problem is the map projection. Specifically, webMercator which has high distortion at high latitudes. In order to do proper length calculations, I first had to project the coordinates into a different projection that handles lengths properly, such as UTM. Once I did that, I could then use getLength properly, as well as other length related activities such as making a line segment of a specific length. I then translate back into webMercator for plotting/display purposes, and everything works as expected.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.