uniapp 复刻 keep 跑步运动轨迹 (获取当前经纬度信息)

发布于:2025-05-13 ⋅ 阅读:(13) ⋅ 点赞:(0)

在这里插入图片描述

"requiredPrivateInfos":[
			"getLocation"
		],
		"permission" : {
		    // 获取当前的地理位置、速度 配置
		    "scope.userLocation" : {
		        "desc" : "你的位置信息将用于小程序位置接口的效果展示"
		    }
		}
<view style="width:100%;height:400px;">
    <map class="map" longitude="105.807244" latitude="37.718127" ref="dcmap" :polyline="polylineObj"
         :scale="15" enable-satellite="true" :enable-poi='true' :enable-building='true'
         :enable-indoorMap='true'></map>
    </view>


data() {
    return {
      polylineObj: [],
    };
  },
  onLoad() {
    uni.getLocation({
      type: 'wgs84', // 默认为 wgs84,表示标准的经纬度坐标系
      success: function (res) {
        console.log('经度: ' + res.longitude);
        console.log('纬度: ' + res.latitude);
      },
      fail: function (err) {
        console.error('获取定位失败: ', err);
      }
    });

    setTimeout(_ => {
      //例如这是请求过来的数据
      const pointList = [{
        "latitude": 37.718127,
        "longitude": 105.807244
      },
        {
          "latitude": 37.718127,
          "longitude": 106.807244
        }, {
          "latitude": 37.718127,
          "longitude": 107.807244
        }, {
          "latitude": 37.718135,
          "longitude": 108.807249
        }, {
          "latitude": 38.218143,
          "longitude": 105.107253
        }, {
          "latitude": 38.018164,
          "longitude": 105.807264
        }, {
          "latitude": 37.918185,
          "longitude": 105.807275
        }, {
          "latitude": 37.818206,
          "longitude": 105.807286
        }, {
          "latitude": 37.7199999,
          "longitude": 105.807297
        }
      ]
      //这里是关键,这里是赋值
      this.polylineObj = [{
        points: pointList,
        arrowLine: true, //配置项:带箭头的线
        arrowIconPath: "/static/point.png", //配置项:更换箭头图标
        width: 10, //配置项:线的宽度
      }, ]
    }, 2000)

  },



网站公告

今日签到

点亮在社区的每一天
去签到