拾取坐标地址:http://api.map.baidu.com/lbsapi/getpoint/index.html
根据坐标绘制多边形区域:https://developer.baidu.com/map/jsdemo.htm#c2_9
将以下的代码复制在打开的地址的源代码编辑器里面运行,拉圈住的红色,把编辑拉开
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";} #allmap {height:100%; width: 100%;} #control{width:100%;} </style> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"></script> <title>设置线、面可编辑</title> </head> <body> <div id="allmap"></div> <div id="control"> <button onclick = "polyline.enableEditing();polygon.enableEditing();">开启线、面编辑功能</button> <button onclick = "polyline.disableEditing();polygon.disableEditing();">关闭线、面编辑功能</button> </div> </body> </html> <script type="text/javascript"> // 百度地图API功能 var map = new BMap.Map("allmap"); map.centerAndZoom(new BMap.Point(108.948264,34.266454), 15); map.enableScrollWheelZoom();
// 记得坐标要首尾一致,形成闭环 var polygon = new BMap.Polygon([ new BMap.Point(108.948148,34.266045), new BMap.Point(108.948713,34.266876), new BMap.Point(108.948148,34.266045) ], {strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5}); //创建多边形 map.addOverlay(polygon); //增加多边形 </script>
#录入到mongodb数据库里面,Polygon是类比,表名是多边形区域【注意注意!!!多边形区域的点不可以相交,否则新增会失败】
db.t_test_place.insert({ xymc:"古都旅馆", polygons:{ type:"Polygon", coordinates:[[ [108.949077,34.266488], [108.949203,34.266492], [108.949212,34.266641], [108.949239,34.266906], [108.949163,34.266913], [108.949104,34.266913], [108.949082,34.266817], [108.949086,34.266764], [108.948916,34.266779], [108.948889,34.266693], [108.949077,34.266671], [108.949068,34.266492], [108.949095,34.266485], [108.949077,34.266488] ]] } } );
#查询以某个点为半径,方圆200米,涉及到的几何区域
db.t_test_place.find({ polygons:{ $geoWithin:{ $centerSphere: [ [ 108.947604,34.267749 ], 0.2 / 6378.1 ] } } })
#判断坐标是否在多边形区域,在的话就会返回数据,不在则返回空
db.t_test_place.find({xymc:"西安市第一中学",polygons:{$geoIntersects:{$geometry:{ "type" : "Point","coordinates" : [113.330908,23.155678] },}}});
标签:map,多边形,Point,mongodb,100%,BMap,new,绘制 From: https://www.cnblogs.com/shendidi/p/16897109.html