Link to home
Start Free TrialLog in
Avatar of SerinaStar
SerinaStarFlag for Australia

asked on

How to calculate distance?

Hi,

I how can I calculate distance between 2 points. I have created a table with the name of towns, post codes and coordinates.

The table look like this:
Town/Site     Post Code    Longitude     Latitude
Moranbah     4740           148.04577   -22.00091

I would like to use the table to give me the distance between the 2 points in Km's.
So If I created 2 combo box's To: and From: a Message Box would appear and say the distance between i.e Moranbah and Dysart is 60.271Km.

Is this possible to do using MS Access 07?
If so where do I begin?

Many Thanks
Serina
Avatar of Anil Kumar
Anil Kumar
Flag of India image

a = sin²(¿lat/2) + cos(lat1).cos(lat2).sin²(¿long/2)
c = 2.atan2(va, v(1-a))
d = R.c
        where R is earth’s radius (mean radius = 6,371km);
note that angles need to be in radians to pass to trig functions!
 javaScript :
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();

var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
ASKER CERTIFIED SOLUTION
Avatar of datAdrenaline
datAdrenaline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SerinaStar

ASKER

Wow your right it does look pretty cool. Do you have any suggestions on how to call the function.
Thanks it is a very interesting piece of code.....it's going to work brillantly    :)