LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   java - jscience: how can I calculate the distance between two LatLong? (http://www.linuxquestions.org/questions/programming-9/java-jscience-how-can-i-calculate-the-distance-between-two-latlong-4175427695/)

 eantoranz 09-17-2012 03:46 PM

java - jscience: how can I calculate the distance between two LatLong?

Hi!

I need to calculate the distance (meters, kmts, whatever) between two Latitude/Longitude positions? I found jscience which I guess is able to do it but I don't know the API.

Could anybody point me to one example?

 abarclay 09-17-2012 10:11 PM

http://www.movable-type.co.uk/scripts/latlong.html

Seems like the "Haversine" formula is an easy solution.
The website even has a sample written in JavaScript.

 ajtucker 09-18-2012 04:47 AM

A quick look at the jscience API doesn't reveal any method of calculating distance, but it may be buried in there somewhere.

I've used the jcoord library before now which has a nice and simple interface, e.g.

Code:

```import uk.me.jstott.jcoord.LatLng; LatLng centre = new LatLng(lat, lon); LatLon somePoi = new LatLon(poiLat, poiLon); Double dist = centre.distance(somePoi);```
Note however, that it looks as though the project website has been hacked, so be careful! I can send along my copy of the jar if it helps.

A more complete set of libraries comes from the GeoTools project, where they use a library by the name of JTS. See http://docs.geotools.org/latest/user...y/api/jts.html for an example of calculating distance with these libraries.

In the end, it may be just as easy to implement the Haversine formula yourself, depending on how accurate you need things to be, the coordinate reference systems being used, where on the Earth you want it to work, etc.

Alex.

 John VV 09-18-2012 05:49 PM

Quote:
 I need to calculate the distance (meters, kmts, whatever) between two Latitude/Longitude positions?
paper and pen are still the best

but are you using a GIS program ?

my self i use ISIS3

more seriously

is this on a "perfect" sphere?
or on the Earth's aeroid
or say the Real distance say from new york to Detroit using the Earth's DEM

 All times are GMT -5. The time now is 01:43 PM.