# java vividsolutions jts wgs-84 distance to meters

my (java) project uses com.vividsolutions.jts.geom, which provides a distance function. After some googling I finally found that the return value from this function is in central angle degrees, when the CRS is WGS-84 (as it is in my project).

What is an easy to implement and accurate on short distances (no need for long distances) conversion from central angle degrees to meters?

I tried converting by dividing by 360 (from degrees), multiplying by 2 * PI (to radians) and multiplying by 6371000 meters, but my answer is off by quite a lot (176m (QGis ellipsoidal ruler tool) vs 204m (mine)).

I found that GeoTools has some conversion functions included, but I would like to not have to depend on another library, since this code is meant to run on the server and an Android client and is meant to be easy to use by other devs.

EDIT: I also emailed the JTS mailing list, and established that wrapping the distance functions for every possible Geometry.distance(geometry) would be a little tedious.

I decided to use the 111 111 m per degree hack described here: Algorithm for offsetting a latitude/longitude by some amount of meters

Thanks for the help, though!

• I don't think the distance that you get from JRS is actually in central angle degrees - it's probably just the cartesian distance between points as if the lat and lon were orthogonal (i couldn't find any other distance function in JTS). Otherwise your approach should give a better result. Sep 9, 2011 at 11:58
• Are you calculating distances between points or other types of geometry? Sep 9, 2011 at 12:05
• @mkadunc I now agree that the StackOverflow answer I found mentioning Central Angle Degrees is probably wrong. And yes, I'm trying to do distance between more complex PolyLines and Points, etc. Sep 13, 2011 at 20:10

I have had reason to pursue a similar goal in the past where accuracy is not of huge importance. We can start by getting the Earth's radius according to the WGS84 Well-Known Text definition.

``````GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
``````

To make sense of the angular distance units, you can use the following formula to convert angular units to meters:

``````angular_units * (PI/180) * 6378137
``````

That should give you a reasonably accurate short-distance measurements in meters. The calculation is based on a perfect sphere (non-ellipsoidal).

The simplest answer is to reproject your map to a better projection. With out knowing where your project is based it's hard to say what a better projection is but if you are dealing with distances then anything but WGS-84 will be better.