前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS开发中使用百度地图计算两点间的距离

iOS开发中使用百度地图计算两点间的距离

作者头像
用户1451823
发布2018-09-13 15:39:28
1.4K0
发布2018-09-13 15:39:28
举报
文章被收录于专栏:DannyHoo的专栏DannyHoo的专栏

版权声明:本文为博主原创文章,未经博主允许不得转载。 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;

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年05月18日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档