2***@qq.com
2***@qq.com
  • 发布:2025-12-19 12:27
  • 更新:2026-02-03 10:35
  • 阅读:141

咨询下uniapp打包h5低于特定版本,高德地图是否消耗“坐标转换”额度,不配置gj02也会强制消耗

分类:uni-app

咨询下uniapp打包h5低于特定版本,高德地图是否消耗“坐标转换”额度,不配置gj02也会强制消耗
场景一
uni.getLocation({
isHighAccuracy: true,
success: res => {
场景二
uni.getLocation({
isHighAccuracy: true,

场景三
uni.startLocationUpdate({
success: () => {}
})
主要这个消耗是低版本强制,还是不区分低高版本都会强制消耗
也就是获取定位用上面api getLocation无法避免
要用其余的方式吗
例如startLocaionUpdate配合onLocationChange替换原本的getLocation

2025-12-19 12:27 负责人:无 分享
已邀请:
Ask小助手

Ask小助手

该问题请在专业群( uni-app 官方技术交流群 1 ) 咨询

根据知识库内容,针对H5平台坐标转换额度消耗问题说明如下:

低于uni-app 4.24版本的H5打包确实存在强制消耗坐标转换额度的情况。核心原因是:

  1. 旧版本(<4.24)H5端uni.getLocationuni.onLocationChange底层依赖腾讯地图的免费gcj02坐标转换接口
  2. 该接口已于2024年7月18日被腾讯逐步下线,导致旧版本H5定位功能异常并可能触发额度消耗
  3. 即使不配置type: 'gcj02',当需要将wgs84坐标转为gcj02(如显示在map组件上)时仍会触发转换

4.24+版本解决方案:

  • 必须在manifest.json的H5配置中填写地图厂商key(高德/腾讯等)
  • 明确指定type: 'wgs84'避免自动转换
  • 对于持续定位场景,uni.startLocationUpdate+uni.onLocationChange组合仍需配置key,但不会额外增加转换次数

特别注意:H5平台使用地图相关功能必须取得商业授权(免费额度有限),否则会消耗服务商配额。建议升级到4.24+并配置自己的地图key,参考文档

若仅需基础定位,可尝试纯wgs84模式(不显示地图),但精度可能受影响。

内容为 AI 生成,仅供参考
2***@qq.com

2***@qq.com (作者) - jianshu.com/u/b7d77a496c1b

最新整改后:

uni.getLocaiton,uni.startUpdateLocationBackground在打包输出h5时会强制消耗高德的坐标转换

因此换成h5原生方法
1 getLocation

navigator.geolocation.getCurrentPosition(  
        position => {  
          let originLat = position.coords.latitude  
          let originLong = position.coords.longitude  
          // 获取经纬度  
          let [latitude, longitude] = qqMapTransGpsMap(originLat, originLong).map(v => v.toFixed(6))  
          runRes = {  
            ...position.coords,  
            longitude  
          }  
        },  
        error => {  
          console.log('getLocation error', error)  
          // openSettingLocation()  
        },  
        {  
          enableHighAccuracy: true,  
          timeout: 5000,  
          maximumAge: 1500 // 缓存定位结果不要设置0  
        }  
      )

2 startUpdateLocationBackground

        // 成功回调  
        position => {  
          // console.log('位置监听成功')  
          // 标记首次启动成功  
          if (!this.locationFirstSuccess) {  
            this.locationFirstSuccess = true  
            this.locationRetryCount = 0 // 重置重试计数  
            // console.log('位置监听首次启动成功')  
          }  

          let originLat = position.coords.latitude  
          let originLong = position.coords.longitude  
          // 获取经纬度  
         //  qqMapTransGpsMap  是自定义方法转换原生wgs48为高德坐标的  网上有开源的不转换则偏移几百米转换则可能几米到十米内  
          let [latitude, longitude] = qqMapTransGpsMap(originLat, originLong).map(v => v.toFixed(6))  
          runRes = {  
            ...position.coords,  
            latitude,  
            longitude  
          }  
          // this.$toast(position.coords.accuracy + '/' + position.coords.speed)  
        },  

        // 错误回调  
        error => {  
          // console.error('位置监听错误:', error.message, '错误码:', error.code)  

          // 根据错误类型处理  
          let errorMessage = ''  
          // console.log(error,error.code)  
          // switch (error.code) {  
          //   case error.PERMISSION_DENIED:  
          //     errorMessage = '位置权限被拒绝'  
          //     break  
          //   case error.POSITION_UNAVAILABLE:  
          //     errorMessage = '位置信息不可用'  
          //     break  
          //   case error.TIMEOUT:  
          //     errorMessage = '位置获取超时'  
          //     break  
          //   default:  
          //     errorMessage = '位置监听错误'  
          // }  

          // 处理重试逻辑  
          this.handleLocationError(errorMessage)  
        },  

        // 配置选项(可选)  
        {  
          enableHighAccuracy: true, // 是否高精度  
          timeout: 5000, // 超时时间(毫秒)  
          maximumAge: 1500 // 缓存位置的最大年龄(毫秒)  
        }  
      )

3 关闭

 if (this.watchId) {  
        navigator.geolocation.clearWatch(this.watchId)  
        this.watchId = null  
      }

要回复问题请先登录注册