帖子
帖子
用户
博客
课程
显示全部楼层
7
帖子
0
勋章
47
Y币

[插件使用] aMap循环调用定位,位置会偏移

[复制链接]
发表于 2021-10-27 15:08:06
  var arr = {} , aMap ,lin = [];    apiready = function(){        aMap = api.require('aMap');        getLocation();        aMap.open({            rect: {                x: 0,                y: 0,                w: 'auto',                h: 'auto'            },            showUserLocation: true,            showsAccuracyRing:false,            zoomLevel: 20,            center: arr,            fixedOn: api.frameName,            fixed: true        });        time();    }    function time(){        setTimeout(function(){            onli();            time();        },500)    }    function getLocation(){        aMap.getLocation(function(ret, err) {            if (ret.status) {                arr.lon = ret.lon,                arr.lat = ret.lat            }         });    }    function onli(){        getLocation();        lin.push(arr)        aMap.setCenter({            coords: arr,            animation: false        });        aMap.addLine({            id: 1,            styles: {                type: 'arrow',                borderColor: '#FF0000',                borderWidth: 3,                lineDash: true,                strokeImg: ''            },            points: lin        });        console.log(JSON.stringify(lin));            }
我就坐在位置上,上面的定位和返回的数据一直再偏移


坐在位置上 位置一值再偏移

坐在位置上   位置一值再偏移
7
帖子
0
勋章
47
Y币
  1.   var arr = {} , aMap ,lin = [];
  2.     apiready = function(){
  3.         aMap = api.require('aMap');
  4.         getLocation();
  5.         aMap.open({
  6.             rect: {
  7.                 x: 0,
  8.                 y: 0,
  9.                 w: 'auto',
  10.                 h: 'auto'
  11.             },
  12.             showUserLocation: true,
  13.             showsAccuracyRing:false,
  14.             zoomLevel: 20,
  15.             center: arr,
  16.             fixedOn: api.frameName,
  17.             fixed: true
  18.         });
  19.         time();

  20.     }

  21.     function time(){
  22.         setTimeout(function(){
  23.             onli();
  24.             time();
  25.         },500)
  26.     }
  27.     function getLocation(){
  28.         aMap.getLocation(function(ret, err) {
  29.             if (ret.status) {
  30.                 arr.lon = ret.lon,
  31.                 arr.lat = ret.lat
  32.             }
  33.         });
  34.     }
  35.     function onli(){
  36.         getLocation();
  37.         lin.push(arr)
  38.         aMap.setCenter({
  39.             coords: arr,
  40.             animation: false
  41.         });
  42.         aMap.addLine({
  43.             id: 1,
  44.             styles: {
  45.                 type: 'arrow',
  46.                 borderColor: '#FF0000',
  47.                 borderWidth: 3,
  48.                 lineDash: true,
  49.                 strokeImg: ''
  50.             },
  51.             points: lin
  52.         });
  53.         console.log(JSON.stringify(lin));
  54.         //上传的代码不清晰再传一次
  55.     }
复制代码
380
帖子
4
勋章
6
Y币
您需要登录后才可以回帖 登录

本版积分规则