프로그래밍/iOS
두 좌표간 거리 구하는 메소드
백룡화검
2012. 10. 20. 22:04
출처 : http://cafe.naver.com/mcbugi/239292
두 좌표간 거리구하는 메소드입니다.
#import <math.h>
/*
좌표계 : WGS84
좌표1 : _x1, _y1
좌표2 : _x2, _y2
*/
- (double)getDistance:(double)_x1 y1:(double)_y1 x2:(double)_x2 y2:(double)_y2
{
double pi = 3.1415;
double theta = _y2 - _y1;
double distance = sin(_x1*pi/180.0) * sin(_x2*pi/180.0) + cos(_x1*pi/180.0) * cos(_x2*pi/180.0) * cos(theta*pi/180.0);
distance = acos(distance);
distance = distance*180.0/pi*60*1.1515*1609.344;
return distance;
}
응용은 여러분의 몫.