Skip to content

getLocation无法获取速度 #1387

@yeancai

Description

@yeancai

问题描述
getLocation无法获取速度 一直为0, 感觉接口没有使用GPS定位

复现步骤

uni.getLocation({
		        type: 'wgs84',
				altitude:true,
				geocode:true,
		        success: function (res) {
		    		console.log(res);
		    		console.log('当前位置的速度:' + res.speed);
		    		uni.showToast({
		    			title: res.speed.toFixed(2),
		    			icon: 'success',
		    			duration: 100
		    		});
		    		if(res.speed!=0){
		    			_self.$set(_self.Gauge.series[0],'data',res.speed / 60)
		    			_self.showGauge('canvasGauge', _self.Gauge);
		    		}
		    		
		        },
				fail: function (res) {
					console.log('失败');
					uni.showToast({
						title: '失败',
						icon: 'success',
						duration: 100
					});
				},
				complete: function (res) {
					console.log('完成');
				}
		    });

预期结果
移动的时候能显示速度

实际结果
一直为0

系统信息:

  • 发行平台: 微信小程序 App
  • 操作系统 Android 10
  • HBuilderX版本2.6.1.20200226
  • 设备信息 小米9

补充信息

根据我的分析,出现这个问题的原因在接口不完善, 微信getLocation也获取不到 但是微信有别的接口调用了GPS可以获取
如下

 wx.startLocationUpdate({
      success: res => console.log('开启小程序接收位置消息成功'),
      fail: err => console.error('开启小程序接收位置消息失败:', err),
      complete: msg => console.log('调用开启小程序接收位置消息API完成')
    })
    wx.onLocationChange(function (res){
      console.log('location change', res.speed)
    })

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions