https://www.cnblogs.com/zhoudi/p/5969671.html
判断点是否在圆中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style type="text/css">
body, html,#allmap { 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=q7RT7IGt5lHWKXzRkPgSCBLoXlYoEBjf"></script>
<script type="text/javascript" src="../lib/GeoUtils.js"></script>
<title>Document</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
//创建地图
var map = new BMap.Map("allmap");
//创建一个圆
var circle = new BMap.Circle(new BMap.Point(112.595384,26.904631),1000,{fillColor:"red", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});
//var point2s = [
// new BMap.Point(112.586149,26.913201),
// new BMap.Point(112.58464,26.909432),
// new BMap.Point(112.585143,26.899219),
// new BMap.Point(112.600953,26.898832),
// new BMap.Point(112.607421,26.900572),
// new BMap.Point(112.606631,26.904825),
// new BMap.Point(112.606523,26.909142),
// new BMap.Point(112.59772,26.909399),
// ];
//创建标注点并添加到地图中
function addMarker(points) {
//循环建立标注点
for(var i=0, pointsLen = points.length; i<pointsLen; i++) {
var marker = new BMap.Marker(points[i]); //将点转化成标注点
map.addOverlay(marker); //将标注点添加到地图上
//添加监听事件
(function() {
var thePoint = points[i];
marker.addEventListener("click",
function() {
showInfo(this,thePoint);
});
})();
}
}
// function showInfo(thisMarker,point) {
// //判断点是否在
// if(BMapLib.GeoUtils.isPointInCircle(point,circle)){
// var infoWindow = new BMap.InfoWindow("在圆形区域内");
// thisMarker.openInfoWindow(infoWindow); //图片加载完后重绘infoWindow
// }else
// {
// var infoWindow = new BMap.InfoWindow("不在圆形区域内");
// thisMarker.openInfoWindow(infoWindow); //图片加载完后重绘infoWindow
// }
// }
function initialize() {
// 百度地图API功能
map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
map.enableScrollWheelZoom(); //启用滚轮放大缩小
map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
var point = new BMap.Point(112.595384,26.904631); // 创建点坐标
map.centerAndZoom(point,15); // 初始化地图,设置中心点坐标和地图级别。
// addMarker(point2s);
map.addOverlay(circle);
}
initialize();
</script>