浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。
 
第2行: 第2行:
 
<div class="bluetitle"><div class="services-title-text service-page-anchor">两点距离计算</div></div>
 
<div class="bluetitle"><div class="services-title-text service-page-anchor">两点距离计算</div></div>
 
根据用户指定的两个坐标点,计算这两个点的实际地理距离。核心代码如下:
 
根据用户指定的两个坐标点,计算这两个点的实际地理距离。核心代码如下:
<pre class="prettyprint codestyle">//导入工具功能包BaiduMapAPI_Utils.framework
+
<div class="code_template"><div class="code_control"><div class="code_btn opt">Objective-C</div><div class="code_btn">Swift</div></div><div class="code_container"><pre class="code_item active prettyprint codestyle">//导入工具功能包BaiduMapAPI_Utils.framework
 
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 
BMKMapPoint point1 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.404)); BMKMapPoint point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(38.915,115.404)); CLLocationDistance distance = BMKMetersBetweenMapPoints(point1,point2);</pre>
 
BMKMapPoint point1 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.404)); BMKMapPoint point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(38.915,115.404)); CLLocationDistance distance = BMKMetersBetweenMapPoints(point1,point2);</pre>
<div class="bluetitle"><div class="services-title-text service-page-anchor">点与圆、多边形的位置关系</div></div>
+
<pre class="code_item prettyprint codestyle">//在桥接头文件BMKSwiftDemo-Bridging-Header中导入工具功能包
 +
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 +
let point1 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.404))
 +
let point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(38.915,115.404))
 +
let distance = BMKMetersBetweenMapPoints(point1,point2)</pre>
 +
</div></div><div class="bluetitle"><div class="services-title-text service-page-anchor">点与圆、多边形的位置关系</div></div>
 
SDK支持判断点与圆或多边形的位置关系,判断点是否在圆内,或者是否在多边形内。
 
SDK支持判断点与圆或多边形的位置关系,判断点是否在圆内,或者是否在多边形内。
  
 
'''{{bluepoint}}判断点与圆位置关系的示例代码如下:'''
 
'''{{bluepoint}}判断点与圆位置关系的示例代码如下:'''
<pre class="prettyprint codestyle">//导入工具功能包BaiduMapAPI_Utils.framework
+
<div class="code_template"><div class="code_control"><div class="code_btn opt">Objective-C</div><div class="code_btn">Swift</div></div><div class="code_container"><pre class="code_item active prettyprint codestyle">//导入工具功能包BaiduMapAPI_Utils.framework
 
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 
BOOL ptInCircle = BMKCircleContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408), CLLocationCoordinate2DMake(39.915,116.404), 1000);</pre>
 
BOOL ptInCircle = BMKCircleContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408), CLLocationCoordinate2DMake(39.915,116.404), 1000);</pre>
 
+
<pre class="code_item prettyprint codestyle">//在桥接头文件BMKSwiftDemo-Bridging-Header中导入工具功能包
 +
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 +
let ptInCircle = BMKCircleContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408), CLLocationCoordinate2DMake(39.915,116.404), 1000);</pre>
 +
</div></div>
 
'''{{bluepoint}}判断点与多边形位置关系的示例代码如下:'''
 
'''{{bluepoint}}判断点与多边形位置关系的示例代码如下:'''
<pre class="prettyprint codestyle">//导入工具功能包BaiduMapAPI_Utils.framework
+
<div class="code_template"><div class="code_control"><div class="code_btn opt">Objective-C</div><div class="code_btn">Swift</div></div><div class="code_container"><pre class="code_item active prettyprint codestyle">//导入工具功能包BaiduMapAPI_Utils.framework
 
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 
CLLocationCoordinate2D coords[5] = {0};
 
CLLocationCoordinate2D coords[5] = {0};
第27行: 第35行:
 
coords[4].latitude = 39.965;
 
coords[4].latitude = 39.965;
 
coords[4].longitude = 116.704;
 
coords[4].longitude = 116.704;
BOOL ptInPolygon = BMKPolygonContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408),coords, 5);
+
BOOL ptInPolygon = BMKPolygonContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408),coords, 5);</pre>
</pre>
+
<pre class="code_item prettyprint codestyle">//在桥接头文件BMKSwiftDemo-Bridging-Header中导入工具功能包
<div class="bluetitle"><div class="services-title-text service-page-anchor">点与折线的位置关系</div></div>
+
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 +
var coords = [CLLocationCoordinate2D]()
 +
coords.append(CLLocationCoordinate2D(latitude: 39.965, longitude: 116.604))
 +
coords.append(CLLocationCoordinate2D(latitude: 39.865, longitude: 116.604))
 +
coords.append(CLLocationCoordinate2D(latitude: 39.865, longitude: 116.704))
 +
coords.append(CLLocationCoordinate2D(latitude: 39.905, longitude: 116.654))
 +
coords.append(CLLocationCoordinate2D(latitude: 39.965, longitude: 116.704))
 +
 
 +
let ptInPolygon = BMKPolygonContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408),&coords, 5)</pre>
 +
</div></div><div class="bluetitle"><div class="services-title-text service-page-anchor">点与折线的位置关系</div></div>
 
SDK还提供获取折线上与折线外指定位置最近点的方法。核心代码如下:
 
SDK还提供获取折线上与折线外指定位置最近点的方法。核心代码如下:
<pre class="prettyprint codestyle">//导入工具功能包BaiduMapAPI_Utils.framework
+
<div class="code_template"><div class="code_control"><div class="code_btn opt">Objective-C</div><div class="code_btn">Swift</div></div><div class="code_container"><pre class="code_item active prettyprint codestyle">//导入工具功能包BaiduMapAPI_Utils.framework
 
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 
BMKMapPoint *polylinePoints = new BMKMapPoint[4];
 
BMKMapPoint *polylinePoints = new BMKMapPoint[4];
第40行: 第57行:
 
BMKMapPoint point = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.815,116.504));
 
BMKMapPoint point = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.815,116.504));
 
BMKMapPoint nearestPoint = BMKGetNearestMapPointFromPolyline(point, polylinePoints, 4);</pre>
 
BMKMapPoint nearestPoint = BMKGetNearestMapPointFromPolyline(point, polylinePoints, 4);</pre>
 +
<pre class="code_item prettyprint codestyle">//在桥接头文件BMKSwiftDemo-Bridging-Header中导入工具功能包
 +
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
 +
var polylinePoints = [BMKMapPoint]()
 +
polylinePoints.append(BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915, 116.404)))
 +
polylinePoints.append(BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915, 116.454)))
 +
polylinePoints.append(BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.975, 116.524)))
 +
polylinePoints.append(BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.855, 116.554)))
 +
 +
let point = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.815, 116.504));
 +
let nearestPoint = BMKGetNearestMapPointFromPolyline(point, &polylinePoints, 4)</pre>
 +
</div></div>

2020年3月26日 (四) 11:29的最后版本

两点距离计算

根据用户指定的两个坐标点,计算这两个点的实际地理距离。核心代码如下:

Objective-C
Swift
//导入工具功能包BaiduMapAPI_Utils.framework
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
BMKMapPoint point1 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.404)); BMKMapPoint point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(38.915,115.404)); CLLocationDistance distance = BMKMetersBetweenMapPoints(point1,point2);
//在桥接头文件BMKSwiftDemo-Bridging-Header中导入工具功能包
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
let point1 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.404))
let point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(38.915,115.404))
let distance = BMKMetersBetweenMapPoints(point1,point2)
点与圆、多边形的位置关系

SDK支持判断点与圆或多边形的位置关系,判断点是否在圆内,或者是否在多边形内。

判断点与圆位置关系的示例代码如下:

Objective-C
Swift
//导入工具功能包BaiduMapAPI_Utils.framework
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
BOOL ptInCircle = BMKCircleContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408), CLLocationCoordinate2DMake(39.915,116.404), 1000);
//在桥接头文件BMKSwiftDemo-Bridging-Header中导入工具功能包
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
let ptInCircle = BMKCircleContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408), CLLocationCoordinate2DMake(39.915,116.404), 1000);

判断点与多边形位置关系的示例代码如下:

Objective-C
Swift
//导入工具功能包BaiduMapAPI_Utils.framework
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
CLLocationCoordinate2D coords[5] = {0};
coords[0].latitude = 39.965;
coords[0].longitude = 116.604;
coords[1].latitude = 39.865;
coords[1].longitude = 116.604;
coords[2].latitude = 39.865;
coords[2].longitude = 116.704;
coords[3].latitude = 39.905;
coords[3].longitude = 116.654;
coords[4].latitude = 39.965;
coords[4].longitude = 116.704;
BOOL ptInPolygon = BMKPolygonContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408),coords, 5);
//在桥接头文件BMKSwiftDemo-Bridging-Header中导入工具功能包
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
var coords = [CLLocationCoordinate2D]()
coords.append(CLLocationCoordinate2D(latitude: 39.965, longitude: 116.604))
coords.append(CLLocationCoordinate2D(latitude: 39.865, longitude: 116.604))
coords.append(CLLocationCoordinate2D(latitude: 39.865, longitude: 116.704))
coords.append(CLLocationCoordinate2D(latitude: 39.905, longitude: 116.654))
coords.append(CLLocationCoordinate2D(latitude: 39.965, longitude: 116.704))

let ptInPolygon = BMKPolygonContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408),&coords, 5)
点与折线的位置关系

SDK还提供获取折线上与折线外指定位置最近点的方法。核心代码如下:

Objective-C
Swift
//导入工具功能包BaiduMapAPI_Utils.framework
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
BMKMapPoint *polylinePoints = new BMKMapPoint[4];
polylinePoints[0]= BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.404));
polylinePoints[1]= BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.454));;
polylinePoints[2]= BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.975,116.524));;
polylinePoints[3]= BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.855,116.554));
BMKMapPoint point = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.815,116.504));
BMKMapPoint nearestPoint = BMKGetNearestMapPointFromPolyline(point, polylinePoints, 4);
//在桥接头文件BMKSwiftDemo-Bridging-Header中导入工具功能包
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
var polylinePoints = [BMKMapPoint]()
polylinePoints.append(BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915, 116.404)))
polylinePoints.append(BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915, 116.454)))
polylinePoints.append(BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.975, 116.524)))
polylinePoints.append(BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.855, 116.554)))

let point = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.815, 116.504));
let nearestPoint = BMKGetNearestMapPointFromPolyline(point, &polylinePoints, 4)
  • 文档根本没法用

  • 文档水平很差

  • 文档水平一般

  • 文档不错

  • 文档写的很好

如发现文档错误,或对此文档有更好的建议,请在下方反馈。问题咨询请前往反馈平台提交工单咨询。

提交反馈

拖动标注工具

添加矩形标注

添加箭头标注

完成

取消