如何计算两个位置的距离?
How to calculate two location distance?
计算两个位置的距离,如果距离大于 5 公里,您必须 return 正确吗?
请帮助我,我是 MapView 的新手。
试试这个
#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
}
假设您有这些点的坐标。
CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
CLLocationDistance distance = [locA distanceFromLocation:locB];
您还需要 #import <CoreLocation/CoreLocation.h>
正如 Dharmesh Dhorajiya
所提到的
计算两个位置的距离,如果距离大于 5 公里,您必须 return 正确吗?
请帮助我,我是 MapView 的新手。
试试这个
#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
}
假设您有这些点的坐标。
CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
CLLocationDistance distance = [locA distanceFromLocation:locB];
您还需要 #import <CoreLocation/CoreLocation.h>
正如 Dharmesh Dhorajiya