LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-17-2012, 03:46 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
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?

Last edited by eantoranz; 09-17-2012 at 03:47 PM.
 
Old 09-17-2012, 10:11 PM   #2
abarclay
LQ Newbie
 
Registered: Aug 2003
Posts: 25

Rep: Reputation: 5
I googled and clicked on the first link.
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.
 
Old 09-18-2012, 04:47 AM   #3
ajtucker
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
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.
 
Old 09-18-2012, 05:49 PM   #4
John VV
Guru
 
Registered: Aug 2005
Posts: 13,516

Rep: Reputation: 1804Reputation: 1804Reputation: 1804Reputation: 1804Reputation: 1804Reputation: 1804Reputation: 1804Reputation: 1804Reputation: 1804Reputation: 1804Reputation: 1804
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

Last edited by John VV; 09-18-2012 at 06:04 PM. Reason: added
 
  


Reply

Tags
distance, gps, java, jscience


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate network bandwidth using java code? SarahRashad Linux - Newbie 1 01-10-2012 01:18 PM
Calculate e^x in Java ckoniecny Programming 6 07-25-2007 11:28 AM
Extending webcam distance RVDowning Mandriva 6 08-31-2006 08:46 AM
administrative distance abirami Linux - Networking 5 09-23-2004 08:02 AM


All times are GMT -5. The time now is 08:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration