具体参看网址: http://bbs.zdoz.net/thread-2-1-1.html
public static double getDistanceFromXtoY(double lat_a, double lng_a, double lat_b, double lng_b) { double pk = (double)(180 / 3.14169); double a1 = lat_a / pk; double a2 = lng_a / pk; double b1 = lat_b / pk; double b2 = lng_b / pk; double t1 = Math.Cos(a1) * Math.Cos(a2) * Math.Cos(b1) * Math.Cos(b2); double t2 = Math.Cos(a1) * Math.Sin(a2) * Math.Cos(b1) * Math.Sin(b2); double t3 = Math.Sin(a1) * Math.Sin(b1); double tt = Math.Acos(t1 + t2 + t3); return 6366000 * tt; } #import <math.h>
-(double)getDistanceTwoGPS:(NSNumber*)lat1 lng1:(NSNumber*)lng1 lat2:(NSNumber*)lat2 lng2:(NSNumber*)lng2 { double pk = (double)(180 / 3.14169); double a1 = [lat1 doubleValue] / pk; double a2 = [lng1 doubleValue] / pk; double b1 = [lat2 doubleValue] / pk; double b2 = [lng2 doubleValue] / pk; double t1 = cos(a1) * cos(a2) * cos(b1) * cos(b2); double t2 = cos(a1) * sin(a2) * cos(b1) * sin(b2); double t3 = sin(a1) * sin(b1); double tt = acos(t1 + t2 + t3); return 6366000 * tt; }