• 小程序计算两者商家与用户之间的距离


    getUserLocation: function () {
    let vm = this;
    wx.getSetting({
    success: (res) => {
    console.log(JSON.stringify(res))
    // res.authSetting['scope.userLocation'] == undefined 表示 初始化进入该页面
    // res.authSetting['scope.userLocation'] == false 表示 非初始化进入该页面,且未授权
    // res.authSetting['scope.userLocation'] == true 表示 地理位置授权
    if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
    wx.showModal({
    title: '请求授权当前位置',
    content: '需要获取您的地理位置,请确认授权',
    success: function (res) {
    if (res.cancel) {
    wx.showToast({
    title: '拒绝授权',
    icon: 'none',
    duration: 1000
    })
    } else if (res.confirm) {
    wx.openSetting({
    success: function (dataAu) {
    if (dataAu.authSetting["scope.userLocation"] == true) {
    wx.showToast({
    title: '授权成功',
    icon: 'success',
    duration: 1000
    })
    //再次授权,调用wx.getLocation的API
    vm.getLocation();
    } else {
    wx.showToast({
    title: '授权失败',
    icon: 'none',
    duration: 1000
    })
    }
    }
    })
    }
    }
    })
    } else if (res.authSetting['scope.userLocation'] == undefined) {
    //调用wx.getLocation的API
    vm.getLocation();
    }
    else {
    //调用wx.getLocation的API
    vm.getLocation();
    }
    }
    })
    },
    // 获取用户的当前位置
    getLocation: function () {
    let that= this;
    wx.getLocation({

    type: 'wgs84',
    success: function (res) {
    var la1 = res.latitude
    var lo2 = res.longitude
    that.setData({
    la1: la1,
    lo2: lo2,
    scale:28
    })
    that.getShangjia(la1, lo2);
    }

    })
    },
    distance: function (la1, lo1, la2, lo2) {
    var La1 = la1 * Math.PI / 180.0;
    var La2 = la2 * Math.PI / 180.0;
    var La3 = La1 - La2;
    var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
    s = s * 6378.137;//地球半径
    s = Math.round(s * 10000) / 10000;
    console.log("计算结果", s)
    this.setData({
    s: s
    })
    },
    //商家
    getShangjia: function (la1, lo2) {
    var that = this;
    app.util.request({
    'url': 'entry/wxapp/Shangjia',
    success: function (res) {
    console.log(res.data.data);
    var shangjia = res.data.data
    for (var i = 0; i < shangjia.length; i++) {
    that.distance(la1, lo2, shangjia[i].s_latitude, shangjia[i].s_longitude)
    shangjia[i].s_shopjuli = that.data.s;
    }
    that.setData({
    shangjia: res.data.data
    })
     
    },
    fail: function (err) {
    console.log(err)
    },
    });
    },
  • 相关阅读:
    Java多线程之“同步”
    50 道 Java 线程面试题(转载自牛客网)
    Ubuntu14.04搭建Caffe(仅CPU)
    【译】OkHttp3 拦截器(Interceptor)
    OkHttp3 使用详解
    JSP ---- 声明、表达式、脚本、注释
    dom解析和sax解析的区别及优缺点
    一个java源文件中为什么只能有一个public类。
    js传入参数为字符串问题
    java project中 xml文件路径问题
  • 原文地址:https://www.cnblogs.com/isuansuan/p/9949016.html
Copyright © 2020-2023  润新知