1. 程式人生 > >js實現定位功能

js實現定位功能

//x x軸 y y軸 _wendu 溫度 _time time _humidity 溼度
function now_one_map01(x, y, _wendu, _time, _humidity, _shebeibianhao, _chepaihao) {
    $("#danMap").html("");// 放地圖的容器
var map01 = new BMap.Map("danMap");
var point = new BMap.Point(x, y);
map01.centerAndZoom(point, 12);
map01.panBy(250,200);//這裡的數值單位是畫素不是百度的經緯度  地圖的中心點
var geoc = new BMap.Geocoder(); //新增地圖到頁面並確定中心點; var marker = new BMap.Marker(point); map01.addOverlay(marker); //新增小紅點; map01.enableScrollWheelZoom(true); geoc.getLocation(point, function(rs) { var addComp = rs.addressComponents; var address = (addComp.province == addComp.city) ? (addComp.city + addComp.district
+ addComp.street + addComp.streetNumber) : (addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber) var _label = new BMap.Label("車牌號:" + _chepaihao + "<br>裝置編號:" + _shebeibianhao + "<br>上報地址:" + address + "<br/>溫/溼度:" + Number(_wendu) / 10 + "℃/"
+ Number(_humidity) / 10 + "%<br/>時間:" + _time, { offset: new BMap.Size(20, -25) }) _label.setStyle({ color: "#046da9", fontSize: "1rem", backgroundColor: "#fefefe", fontWeight: "normal", border: "1px solid #ff892a" }); marker.setLabel(_label); }); }