之前在项目中一直使用高德进行地图的功能实现。所以在项目中会遇到一些小的计算。为了方便以后查阅以及方便小伙伴们的使用,所以就将方法整理下来。那我们开始吧。
- 计算距离
//1.将两个经纬度点转成投影点
MAMapPoint point1 = MAMapPointForCoordinate(CLLocationCoordinate2DMake(39.989612,116.480972));
MAMapPoint point2 = MAMapPointForCoordinate(CLLocationCoordinate2DMake(39.990347,116.480441));
//2.计算距离
CLLocationDistance distance = MAMetersBetweenMapPoints(point1,point2);```
* 判断点是否在圆内
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(39.989612,116.480972);
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(39.990347,116.480441);
BOOL isContains = MACircleContainsCoordinate(location, center, 200);```
- 判断点是否在可视范围
//1.将annotation的经纬度点转成投影点
MAMapPoint point = MAMapPointForCoordinate(annotation.coordinate);
//2.判断该点是否在地图可视范围
BOOL isContains = MAMapRectContainsPoint(mapview.visibleMapRect, point);```
今天稍微整理三条,有时间继续整理。期待接下来的高德路线规划、导航的demo学习吧。