mapcontext.polygoncontainspoint(object object)
基础库 或更高版本; 且 支付宝客户端 10.2.33 或更高版本; 若版本较低,建议采取 兼容处理 。
支小宝客户端 支持
安诊儿客户端 支持
小程序开发者工具: 支持。3.8.4 或更高版本
主体: 企业支付宝小程序 、 个人支付宝小程序
判断多边形区域是否包含指定的坐标点。
object object
查看示例
属性 | 类型 | 默认值 | 必填 | 描述 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
polygon | array | - | 是 | 多边形区域的所有顶点坐标 |
||||||||||
|
||||||||||||||
point | object | - | 是 | 需要判断位置的坐标点 |
||||||||||
|
||||||||||||||
success | function | - | 否 | 调用成功的回调函数 |
||||||||||
fail | function | - | 否 | 调用失败的回调函数 |
||||||||||
complete | function | - | 否 | 调用结束的回调函数(调用成功、失败都会执行) |
fail 回调的参数为 object,error
属性为错误码,errormessage
属性为错误消息。
错误码 | 错误消息 | 凯发app官方网站的解决方案 |
---|---|---|
2 | 接口参数无效 |
请检查入参 point 或 polygon 是否正确。 |
mapcontext.polygoncontainspoint axml 代码
mapcontext.polygoncontainspoint js 代码
<view>
<map id="map" style="width:100%; height:500px"/>
<button ontap="polygoncontainspoint">判断多边形区域是否包含指定的坐标点button>
view>
page({
data: {
mapctx: null,
},
onready() {
this.data.mapctx = my.createmapcontext("map");
},
polygoncontainspoint() {
var points = [
{
latitude: 30.273960,
longitude: 120.124872,
},
{
latitude: 30.271960,
longitude: 120.124872,
},
{
latitude: 30.271960,
longitude: 120.126872,
},
{
latitude: 30.273960,
longitude: 120.126872,
},
];
this.data.mapctx.polygoncontainspoint({
polygon: points,
point: {
latitude: 30.272960,
longitude: 120.126872,
},
success: res => {
console.log(res)
},
fail: error => {
console.log(error)
}
});
},
});
-
tip安卓客户端 10.3.60 之前的版本中,入参 point 或 polygon 错误时会返回错误码 60103。
-
bug传入的点若在区域边角上,安卓会返回 true (点在区域内),ios 会返回 false (点在区域外)。