1.百度地图api js有提供计算坐标点包含的函数,使用前需引入
<script type="text/javascript" src="http://api.map.baidu.com/library/GeoUtils/1.2/src/GeoUtils_min.js"></script>
2.编写js
//多边形覆盖物坐标
var overlays = [
new BMap.Point(106.602849,29.562462),new BMap.Point(106.635619,29.595882),
new BMap.Point(106.65143,29.571383),new BMap.Point(106.620532,29.512593),
new BMap.Point(106.5948,29.52815),new BMap.Point(106.602849,29.562462)
];
function ptInPolygon(point){ //判断传入的points点是否在ply多边形里面,是返回true,否返回false
var ply = new BMap.Polygon(overlays);
var result = BMapLib.GeoUtils.isPointInPolygon(point, ply);
if(result==true){
return true;
}else{
return false;
}
}