Created
May 19, 2015 09:00
-
-
Save radianttap/4b5745bb6739405ad070 to your computer and use it in GitHub Desktop.
GeoDistance between two points using lat/long, per http://stackoverflow.com/questions/2010466/how-can-i-determine-the-distance-between-two-sets-of-lattitude-longitude-coordin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double ToRadians(double degrees) { return degrees * M_PI / 180; } | |
- (NSNumber *)geoDistanceFromLat:(CLLocationDegrees)lat1 fromLon:(CLLocationDegrees)lng1 toLat:(CLLocationDegrees)lat2 toLon:(CLLocationDegrees)lng2 { | |
CLLocationDistance EarthRadiusInMeters = 6367000.0; | |
CLLocationDistance distance = EarthRadiusInMeters * 2 * | |
asin(fmin(1, sqrt((pow(sin((ToRadians(lat2) - ToRadians(lat1)) / 2.0),2.0) | |
+ | |
cos(ToRadians(lat1)) * cos(ToRadians(lat2)) | |
* | |
pow(sin((ToRadians(lng2) - ToRadians(lng1)) / 2.0), 2.0) | |
) | |
) | |
) | |
); | |
return @(distance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment