HTML5获取手机方位角并在地图实时显示

1 技术路线

HTML5、Vue、Leaflet(用于呈现地图)、leaflet-rotatedmarker(用于旋转marker定位点),需要https部署。

2 实现流程

2.1 初始化leaflet并显示地图:

initMap() {
   
   
      var tVue = this;
      tVue.map = L.map("map", {
   
   
        center: [36.66374, 117.141833],
        zoom: 15,
        crs: L.CRS.EPSG4326
      });

      var token = "你的token";
      var tdt_sd = L.tileLayer('https://service.sdmap.gov.cn/tileservice/sdpubmap?layer=SDPubMap&style=default&tilematrixset=default028mm&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=' + token, {
   
   
        zoomOffset: 1, // 注意crs为EPSG4326有偏移
        noWrap: true,
        bounds: [[-90, -180], [90, 180]],
        crs: L.CRS.EPSG4326
      });
      tVue.map.addLayer(tdt_sd);
    }

2.2 获取当前位置,添加定位图标

var tVue = this;
//获取当前位置
navigator.geolocation.getCurrentPosition(function (position) {
   
   
   //添加位置图标
   tVue.addLocMarker(position.coords.latitude, position.coords.longitude);
 }, function (err) {
   
   
   console.log("geolocation error", err.message);
 });
addLocMarker(lat, lng) {
   
   
  var tVue = this;
  if (tVue.locMarker == null) {
   
   
    var icon = L.icon({
   
   
      iconUrl: imageCurrPosition,
      iconSize
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值