我们在使用到百度地图的项目中可能会需要计算两点间的距离,我们可以很容易通过百度地图的开发文档中找到计算两点间距离的方法:
BMKMapPoint point1 = BMKMapPointForCoordinate(userLocation.location.coordinate);
BMKMapPoint point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(model.latitude,model.longitude));
CLLocationDistance distance = BMKMetersBetweenMapPoints(point1,point2);
BaiduMapAPI_Utils/BMKUtilsComponent.h
计算出的距离单位是米。
在没找到该头文件前我本来是想放弃百度地图的这个方法而使用原生的方法的,原生的方法:
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:userLocation.location.coordinate.latitude longitude:userLocation.location.coordinate.longitude];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:model.latitude longitude:model.longitude] ;
CLLocationDistance distance = [location1 distanceFromLocation:location2];