How to calculate distance and bearing between Latitude/Longitude points

Hello,

Does anyone know how to calculate distance and bearing between Latitude/Longitude points? I am trying to determine the distance in feet but I can convert it if available in another format. And I would love to know the bearing. I know people use these methods for apps such as finding your car, etc. I am doing the same thing but for another use. So I would love to show an arrow to point in the direction of the bearing.

Thanks!

Warren

You should be able to port the javascript code available here to Lua - http://www.movable-type.co.uk/scripts/latlong.html

I believe this is correct for the distance:

function calculateDistance(latitudeA, latitudeB, longitudeA, longitudeB) local radius = 6367000 --rough average radius of earth local radian = math.pi / 180 local deltaLatitude = math.sin(radian \* (latitudeA - latitudeB) \* 0.5) local deltaLongitude = math.sin(radian \* (longitudeA - longitudeB) \* 0.5) local circleDistance = 2 \* math.asin(math.min(1, math.sqrt(deltaLatitude \* deltaLatitude + math.cos(radian \* latitudeA) \* math.cos(radian \* latitudeB) \* deltaLongitude \* deltaLongitude))) return radius \* circleDistance end

Obviously latitudeA, latitudeB, longitudeA and longitudeB are your lat+long points you want to calculate between. This is code I had in one of my previous projects, I believe it returns the distance in meters. If anyone has spotted a mistake then let me know.

You should be able to port the javascript code available here to Lua - http://www.movable-type.co.uk/scripts/latlong.html

I believe this is correct for the distance:

function calculateDistance(latitudeA, latitudeB, longitudeA, longitudeB) local radius = 6367000 --rough average radius of earth local radian = math.pi / 180 local deltaLatitude = math.sin(radian \* (latitudeA - latitudeB) \* 0.5) local deltaLongitude = math.sin(radian \* (longitudeA - longitudeB) \* 0.5) local circleDistance = 2 \* math.asin(math.min(1, math.sqrt(deltaLatitude \* deltaLatitude + math.cos(radian \* latitudeA) \* math.cos(radian \* latitudeB) \* deltaLongitude \* deltaLongitude))) return radius \* circleDistance end

Obviously latitudeA, latitudeB, longitudeA and longitudeB are your lat+long points you want to calculate between. This is code I had in one of my previous projects, I believe it returns the distance in meters. If anyone has spotted a mistake then let me know.