agileaholic :)

Java, groovy, grails, hacking and more…

How to compute distance between two places

Posted by Prabhu Beeman on January 17, 2009

After successful implementation of my previous project I started working on my new project which is confidential :-)

I was trying to figure out if i could compute distance between 2 places which is one of the requirements for my project. After searching for about 4-5 hrs, I got what i want although not very precise.

Basically, you need the latitude and longitude of the places for which you need the distance. Thanks to the Yahoo Maps – GeoCoding API. You just need to provide the necessary details (like the location/city/country) and you get the latitude and longitude of the location.
In order to compute the distance you can use Haversine formula. Here is the java implementation.
It provides the result in nautical miles….

1 nautical mile = 1.85200 kms

I tried calculating distance between some of the places in chennai, India and it worked great.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>