Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 2340

# Longitude Latitude distance calculation

I am doing an application in Xcode with Applescript and shell scripts ...
... do anyone know how I can get a distance between two points (long1, lat1, long2, lat2)
based on this formula (with apple or shell script?):

Distance between points:
The great circle distance d between two points with coordinates {lat1,lon1} and {lat2,lon2} is given by:

d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))

A mathematically equivalent formula, which is less subject to rounding error for short distances is:

d=2*asin(sqrt((sin((lat1-lat2)/2))^2 +
cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))

Thanks!
0
Hans Inge Hagen
1 Solution

Commented:
#!/bin/sh
perl -MMath::Trig -e '\$_*=pi/180 for (\$lat1,\$lon1,\$lat2,\$lon2)=@ARGV;print 2*asin(sqrt((sin((\$lat1-\$lat2)/2))**2 + cos(\$lat1)*cos(\$lat2)*(sin((\$lon1-\$lon2)/2))**2))*180/pi' 0 0 10 10
0

Owner and programmerAuthor Commented:
Do you also knoe haw to add varibles combinding applescript and perl?
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.