如何计算两个位置距离?

时间:2015-07-02 09:14:25

标签: ios mkmapview

计算两个位置距离,如果距离大于5公里,则必须返回true?

Plz帮助我,我是MapView的新手。

2 个答案:

答案 0 :(得分:0)

试试这个

#import <CoreLocation/CoreLocation.h>

 CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];

 CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];

 CLLocationDistance distance = [locA distanceFromLocation:locB];

 //Distance in Meters

if((distance*1000)>5)
{
    //return true;
    // your coding
}

答案 1 :(得分:0)

假设你有点的坐标。

CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];

 CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];

 CLLocationDistance distance = [locA distanceFromLocation:locB];

你还需要Dharmesh Dhorajiya提到的#import <CoreLocation/CoreLocation.h>