6***@qq.com
6***@qq.com
  • 发布:2023-11-07 11:44
  • 更新:2023-12-15 11:50
  • 阅读:566

uni.offLocationChange不生效

分类:uni小程序sdk

end() {
uni.offLocationChange(function (res) {
console.log(res);
});
},

2023-11-07 11:44 负责人:HRK_01 分享
已邀请:
1***@qq.com

1***@qq.com

我也出现了该问题,未解决

YUANRJ

YUANRJ

什么平台?vue2还是vue3

  • 2***@qq.com

    vue3

    2024-02-01 14:12

  • YUANRJ

    回复 2***@qq.com: 详细描述下

    2024-02-01 14:28

  • 2***@qq.com

    回复 YUANRJ: app端,打开gps后只输出经度纬度和’停止‘,没有输出’关闭‘,,,,代码:onLocation(){

    let that=this;

    uni.startLocationUpdate({

    type:'gcj02',

    success:res=>{

    uni.onLocationChange(function(res){

    that.real_la=res.latitude;

    that.real_long=res.longitude;

    console.log(经度: ${that.real_la},纬度: ${that.real_long})

    uni.stopLocationUpdate({

    success:res2=>{

    console.log('停止')

    }

    })

    uni.offLocationChange(function(res){

    console.log('关闭')

    })

    })

    },

    fail:err=>{

    console.error('失败',err)

    uni.showToast({

    title:'位置获取失败,尝试打开GPS后再试',

    icon:'none',

    })

    }


        })  
    },

    2024-02-01 14:34

  • HRK_01

    回复 2***@qq.com: offLocationChange是用来取消订阅该回调函数,具体的引用应该和onLoacationChange指向同一个cb。


    onLocation() {  
    let that = this;
    let cb = (res) =>{
    console.log("激活一次",res);
    }
    uni.startLocationUpdate({
    type: 'gcj02',
    success: res => {
    uni.onLocationChange(cb)
    uni.offLocationChange(cb)
    uni.offLocationChangeError(cb)
    uni.stopLocationUpdate({
    success: res2 => {
    console.log('停止')
    }
    })
    },
    fail: err => {
    console.error('失败', err)
    uni.showToast({
    title: '位置获取失败,尝试打开GPS后再试',
    icon: 'none',
    })
    }
    })

    2024-02-02 14:40

  • 2***@qq.com

    回复 DCloud_UNI_HR控制台没有输出啊

    2024-02-03 14:19

要回复问题请先登录注册