通过百度地图api实现人员定位功能,采用前后端分离技术,定位手环定时发送经纬度值到服务器,前端通过接口定时刷新定位显示内容,实现人员定位功能。
前端代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=你的ak"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<title>根据经纬度定位</title>
<style>
html, body, #allmap{
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
#result{
padding: 7px 10px;
position: fixed;
top: 10px;
left: 20px;
width: 550px;
background: #fff;
box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
border-radius: 7px;
z-index: 99;
}
#result input{
width:130px;
margin-right:10px;
height:25px;
border: 1px solid rgba(27, 142, 236, 0.5);
border-radius: 5px;
}
#result button{
border: 1px solid rgba(27, 142, 236, 0.5);
border-radius: 5px;
background: rgba(27, 142, 236, 0.5);
color: #fff
}
.BMap_bubble_title{
font-size: 16px;
}
.BMap_bubble_center{
font-size: 14px;
}
</style>
</head>
<body>
<div id='allmap'></div>
<div id='result'>
经度: <input id="lng" type="text"/>
纬度: <input id="lat" type="text"/>
<button onclick="theLocation()"/>查询</button>
<button onclick="getLocation()"/>定位</button>
<button onclick="clearMarker()"/>清除标记</button>
</div>
<script>
var map = new BMapGL.Map("allmap");
map.centerAndZoom(new BMapGL.Point(116.404, 39.928), 15);
map.enableScrollWheelZoom(true);
function theLocation(){
var lng=$("#lng").val();
var lat=$("#lat").val();
if(lng != "" && lat!= ""){
setMarker(lng,lat);
}
}
function getLocation(){
var geolocation = new BMapGL.Geolocation();
geolocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
$("#lng").val(r.point.lng);
$("#lat").val(r.point.lat);
}
else {
alert('获取定位失败:'+this.getStatus());
}
});
}
function setMarker(lng,lat){
var point=new BMapGL.Point(lng, lat);
var marker = new BMapGL.Marker(point);
map.addOverlay(marker);
var opts = {
width : 200,
height: 100,
title : "人员信息 32090001" ,
message:"刘雅文,心率正常,血氧浓度正常,手环状态<span style='color:red;'>异常</span>"
}
var infoWindow = new BMapGL.InfoWindow(opts.message, opts);
marker.addEventListener("click", function(){
map.openInfoWindow(infoWindow, point);
});
map.centerAndZoom(point, 15);
}
function clearMarker(){
map.clearOverlays();
}
</script>
</body>
</html>