版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1337754
我们在使用到百度地图的项目中可能会需要计算两点间的距离,我们可以很容易通过百度地图的开发文档中找到计算两点间距离的方法:
BMKMapPoint point1 = BMKMapPointForCoordinate(userLocation.location.coordinate);
BMKMapPoint point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(model.latitude,model.longitude));
CLLocationDistance distance = BMKMetersBetweenMapPoints(point1,point2);
可该代码不能直接使用,因为我们还需要导入一个头文件,反正我在百度地图开发文档中没有直接找到该头文件(可能找的不够仔细)。最后是在iOS技术交流群被告知了这个头文件:
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;
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有