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:
esri.geometry.getUnitValueForSR(monMap.map.spatialReference)
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?
geodesicUtils.geodesicLengths
?