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
  • Last Modified:

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
Asked:
Hans Inge Hagen
1 Solution
 
ozoCommented:
#!/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
 
Hans Inge HagenOwner and programmerAuthor Commented:
Do you also knoe haw to add varibles combinding applescript and perl?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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