[英]How to calculate two location distance?
calculate two locations distance if distance is greater than 5 Kms you have to return true?计算两个位置的距离,如果距离大于 5 公里,您必须返回 true?
Plz help me,i am new to MapView.请帮助我,我是 MapView 的新手。
try this尝试这个
#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
}
Assuming you have coordinates of the points.假设你有这些点的坐标。
CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
CLLocationDistance distance = [locA distanceFromLocation:locB];
Also you need to #import <CoreLocation/CoreLocation.h>
as mentioned by Dharmesh Dhorajiya您还需要
#import <CoreLocation/CoreLocation.h>
如 Dharmesh Dhorajiya 所述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.