Skip to content

Calculate the distance betweens two GPS coordinates with the Haversine Formular.

License

Notifications You must be signed in to change notification settings

carlj/CJAHaversine

Repository files navigation

#CJAHaversine Calculate the distance betweens two GPS coordinates with the Haversine Formular.

As of iOS 7 release, you can use the MKDistanceFormatter Class to calculate the distance between two locations.

Build Status Coverage Status

##Installation

  • Drag & Drop CJAHaversine.h and CJAHaversine.m to your project

If you want to use the CLLocationCoordinate2D functions:

  • Add the CoreLocation framework to your target
  • Import <CoreLocation/CoreLocation.h> to your targets ...-Prefix.pch file

##Usage calculate the distance in the imperial system:

//Calculate the distance between two location in kilometers
distance = CJAHaversineMilesBetweenLocations(lat1, lon1, lat2, lon2);

//Calculate the distance between two location in meters
distance = CJAHaversineFeetsBetweenLocations(lat1, lon1, lat2, lon2);

calculate the distance in the metric system:

//Calculate the distance between two location in kilometers
distance = CJAHaversineKilometersBetweenLocations(lat1, lon1, lat2, lon2);

//Calculate the distance between two location in meters
distance = CJAHaversineMetersBetweenLocations(lat1, lon1, lat2, lon2);

You can also use the CLLocationCoordinate2D struct from the CoreLocation framework:

//Calculate the distance between two `CLLocationCoordinate2D` in miles
distance = CJAHaversineMilesBetweenCLLocations(first, second);

//Calculate the distance between two `CLLocationCoordinate2D` in feets
distance = CJAHaversineFeetsBetweenCLLocations(first, second);

//Calculate the distance between two `CLLocationCoordinate2D` in kilometers
distance = CJAHaversineKilometersBetweenCLLocations(first, second);

//Calculate the distance between two `CLLocationCoordinate2D` in meters
distance = CJAHaversineMetersBetweenCLLocations(first, second);

##License Released under the MIT license.

About

Calculate the distance betweens two GPS coordinates with the Haversine Formular.

Resources

License

Stars

Watchers

Forks

Packages

No packages published