收藏
回答

获取地理位置授权点击允许没有获取到地理位置

微信定位关闭的情况下,打开网页会提示获取地理位置,点击允许后,没有获取到地理位置,getLocation方法没有调用,刷新,返回上一页都没有作用

回答关注问题邀请回答
收藏

1 个回答

  • 灵芝
    灵芝
    2018-08-09

    你好,你说的打开网页是指公众号还是小程序内呢?能否提供相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)?

    2018-08-09
    有用
    回复 1
    • 久不愈
      久不愈
      2018-08-09

      打开公众号

      var u = navigator.userAgent;

      var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端

      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

      if (isiOS == true) {

      if (localStorage.getItem("pagerole") == "visittime") {

      var urldata = global_.getRandColor() + "/history";

      } else {

      var urldata = global_.getRandColor() + "/functionmap";

      }

      } else {

      var urldata = window.location.href;

      }

      let that = this;

      let condition = {

      url: urldata

      };


      let promise = api.queryaddresss(condition);

      promise.then(function(response) {

      if (response.status === 200 && response.data.success === true) {

      that.wxConfig = response.data.datas;

      wx.config({

      debug: true,

      appId: globalConfig.CORPID,

      timestamp: that.wxConfig.signTime,

      nonceStr: that.wxConfig.nonceStr,

      signature: that.wxConfig.signConfig,

      jsApiList: [

      // 所有要调用的 API 都要加到这个列表中

      "checkJsApi",

      "getLocation",

      "openLocation",

      "chooseImage",

      "uploadImage",

      "downloadImage"

      ]

      });

      wx.ready(function() {

      wx.getLocation({

      type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'

      success: function(res) {

      that.isaddress = false;

      that.latitude = Number(res.latitude); // 纬度,浮点数,范围为90 ~ -90

      that.longitude = Number(res.longitude); // 经度,浮点数,范围为180 ~ -180。

      that.speed = res.speed; // 速度,以米/每秒计

      that.accuracy = res.accuracy; // 位置精度

      //用高德地图通过经纬度确定具体地址

      // var map = new AMap.Map("app", {

      //   resizeEnable: true,

      //   zoom: 18

      // }),

      let lnglatXY = [that.longitude, that.latitude]; //已知点坐标

      function regeocoder() {

      //逆地理编码

      var geocoder = new AMap.Geocoder({

      radius: 1000,

      extensions: "all"

      });

      geocoder.getAddress(lnglatXY, function(status, result) {

      if (status === "complete" && result.info === "OK") {

      geocoder_CallBack(result);

      }

      });

      var marker = new AMap.Marker({

      //加点

      map: map,

      position: lnglatXY

      });

      map.setFitView();

      }

      function geocoder_CallBack(data) {

      var address = data.regeocode.formattedAddress; //返回地址描述

      that.myaddress = address;

      // console.log(that.myaddress)

      // document.getElementById("result").innerHTML = address;

      }

      regeocoder();

      },

      cancel: function(res) {

      console.log("用户拒绝授权");

      that.isaddress = true;

      },

      fail: function () {


      alert("定位关闭了")


      }

      });

      });

      }





      });


      2018-08-09
      回复
登录 后发表内容