收藏
回答

map相关

iPhone真机调试出现ReferenceError: define is not defined,导致最后在手机显示时拖拽地图一直闪拖不动

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

1 个回答

  • 疯狂的小辣椒
    疯狂的小辣椒
    2019-01-22

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2019-01-22
    有用
    回复 4
    • 張小小
      張小小
      2019-01-22

      出现问题是在iPhone12以上微信新版,iOS11的微信旧版也没问题,一下是index页面代码:


      const app = getApp()var circles = []; var controls = []; var theMap; var lat; var long; var circleRadius; var windowWidth; var windowHeight; var con = []; var lists = []; var positionAddress; var dotted; var getMessageFlag;

      Page({

      data: {

      scale: 13,   searchText: "",

      canIUse: wx.canIUse('button.open-type.getUserInfo'),

      showOrHidden: false,showOrHiddenMap: true,theLoginCode: ""

      },

      onLoad: function() {

      getMessageFlag = false;

      var that = this;

      wx.login({

      success: function(loginCode) {

      that.setData({theLoginCode: loginCode.code})

      // 查看是否授权

      wx.getSetting({

      success: function(res) {

      if (res.authSetting['scope.userInfo']) {

      that.setData({

      showOrHidden: false,

      showOrHiddenMap: true})

      wx.getUserInfo({

      success: function(res) {

      var encryptedData = res['encryptedData'];

      var iv = res['iv'];

      console.log('login code: ');

      wx.request({

      url: 'login的请求',

      header: {"Content-Type": "application/x-www-form-urlencoded"},

      method: "POST",

      data: that.json2Form({

      loginCode: that.data.theLoginCode,

      encryptedData: encryptedData,

      iv: iv}),

      success: function(res) {

      },

      fail(err) {console.log(err, '获取用户信息失败')}});}else{

      console.log(res.authSetting);

      that.setData({

      showOrHidden: true,

      showOrHiddenMap: false})}}})}})

      circleRadius = 3000;

      wx.getSystemInfo({

      success: function(res) {

      windowWidth = res.windowWidth;

      windowHeight = res.windowHeight;

      con = [{

      id: 1,typea: "areaBG",iconPath: '../../img/kmBG.png',position: {left: 23,top: 81,width: 61.5,height: 122},

      clickable: false},

      {id: 2,iconPath: '../../img/sure_position.png',position: {left: (res.windowWidth - 80) / 2,top: 100,width: 80,height: 30},clickable: true},

      {id: 3,typea: "arealist",iconPath: '../../img/aero.png',

      position: {

      left: 30,top: 88,width: 47.5,height: 36},

      clickable: true},

      {id: 4, //2KMtypea: "arealist",iconPath: '../../img/aero.png',

      position: {

      left: 30,top: 124,width: 47.5,height: 36},clickable: true},

      {id: 5, //3KMtypea: "arealist",iconPath: '../../img/3km.png',

      position: {

      left: 30,top: 160,width: 47.5,height: 36},

      clickable: true},

      {id: 6,

      iconPath: '../../img/choose_position@2x.png',

      position: {

      left: (res.windowWidth - 24) / 2, //在地图中间top: (res.windowHeight - 70 + windowHeight * 0.07) / 2,

      width: 24,height: 33},

      clickable: false},]

      for (var i = 0; i < con.length; i++) {

      var obj = con[i];

      if (obj.typea == "arealist") {

      lists.push(obj);}}

      that.setData({controls: con})}})

      app.getLocationInfo(function(locationInfo) {

      that.long = locationInfo.longitude;

      that.lat = locationInfo.latitude;

      that.setData({

      longitude: locationInfo.longitude,

      latitude: locationInfo.latitude,

      scale: 13,})

      circles: [{

      latitude: locationInfo.latitude,

      longitude: locationInfo.longitude,

      fillColor: '#7cb5ec88',

      color: '000000',

      radius: circleRadius,}]

      that.getAddress()})

      theMap = wx.createMapContext("theMap");},

      bindGetUserInfo: function(e) {

      console.log(e.detail.userInfo)

      var that = this;

      that.setData({

      showOrHidden: false,

      showOrHiddenMap: true})

      if (e.detail.userInfo != "undefined") {

      wx.getUserInfo({

      success: function(res) {

      var encryptedData = res['encryptedData'];var iv = res['iv']; //iv

      console.log('login code: ');

      console.log(that.data.theLoginCode);

      wx.request({

      url: 'login请求',

      header: {

      "Content-Type": "application/x-www-form-urlencoded"

      },

      method: "POST",

      data: that.json2Form({

      loginCode: that.data.theLoginCode,

      encryptedData: encryptedData,

      iv: iv

      }),

      success: function(res) {

      },

      fail(err) {

      console.log(err, '获取用户信息失败')}});}},

      //定位

      locationBtn() {

      var that = this;

      app.getLocationInfo(function(locationInfo) {

      that.long = locationInfo.longitude;

      that.lat = locationInfo.latitude;

      that.setData({

      longitude: locationInfo.longitude,

      latitude: locationInfo.latitude,

      scale: 13

      })

      circles: [{

      latitude: locationInfo.latitude,

      longitude: locationInfo.longitude,

      fillColor: '#7cb5ec88',

      color: '000000',

      radius: circleRadius,}]})},

      //处理json数据,用于POST请求构造body

      json2Form(json) {

      var str = [];

      for (var p in json) {

      str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));}

      return str.join("&");},

      //获取地图中心点经纬度,重新绘制圆圈等

      getLngLat: function() {

      var that = this;

      theMap.getCenterLocation({

      success: function(res) {

      console.log("long,lat:" + res.longitude + "," + res.latitude);

      that.setData({

      longitude: res.longitude,

      latitude: res.latitude,

      // scale: that.data.scale

      circles: [{

      latitude: res.latitude,

      longitude: res.longitude,

      color: '000000',

      fillColor: '#7cb5ec88',

      radius: circleRadius,}]})

      that.lat = res.latitude;

      that.long = res.longitude;}})

      that.getAddress();

      },





      2019-01-22
      回复
    • 張小小
      張小小
      2019-01-22

      //地图位置变更触发

      regionchange(e) {

      var that = this;

      if (e.type == 'end') {

      that.getLngLat();}},

      controltap(e) {

      var theId = e.controlId;

      var that = this;

      if (theId > 2 && theId < 6) {

      var imgList = new Array('../../img/1km.png', '../../img/2km.png', '../../img/3km.png');

      var target;

      for (var i = 0; i < lists.length; i++) {

      var obj = lists[i];

      if (obj.id == e.controlId) {

      var intA = obj.id - 3;

      obj.iconPath = imgList[intA];

      } else {

      obj.iconPath = '../../img/aero.png';}}

      that.setData({

      controls: con,})

      that.setDotted(dotted);

      switch (theId) { //分别执行点击1、2、3km方法

      case 3:

      that.click_1km(e);

      break;

      case 4:

      that.click_2km(e);

      break;

      case 5:

      that.click_3km(e);

      break;}

      } else if (theId == 2) { //如果点击了2,则确认位置,开始市调

      that.sure_position(e);}},

      //确认位置方法

      sure_position(e) {

      var that = this;

      wx.navigateTo({

      url: '../detail/detail?long=' + that.long + '&lat=' + that.lat + '&radius=' + circleRadius,})},

      click_1km(e) {

      circleRadius = 1000;

      this.getLngLat();

      this.setScale(14);},

      click_2km(e) {

      circleRadius = 2000;

      this.getLngLat();

      this.setScale(13);},

      click_3km(e) {

      circleRadius = 3000;

      this.getLngLat();

      this.setScale(13);},

      //设置缩放比

      setScale(scaleA) {

      var that = this;

      that.data.scale = scaleA;

      that.setData({

      scale: scaleA})},

      getAddress() {

      var that = this;

      var urll = "https://restapi.amap.com/v3/geocode/regeo?key=" + app.globalData.baseWebUrl+"&location=" + that.long + "," + that.lat + "&output=json&radius=" + that.radius + "&extensions=all";

      // const task =

      wx.request({

      url: urll,

      success: function(res) {

      that.positionAddress = res['data']['regeocode']['formatted_address'];

      console.log("that.positionAddress:" + that.positionAddress);

      that.setData({

      searchText: that.positionAddress})}})},

      getLocation(address) {

      var that = this;

      var urll = "https://restapi.amap.com/v3/geocode/geo?key=" + app.globalData.baseWebUrl+"&address=" + address;

      wx.request({

      url: urll,

      success: function(res) {

      var obj = res['data'];

      var geocodes = obj['geocodes'];

      if (geocodes.length) {

      var location = geocodes[0]['location'];

      var arr = location.split(',');

      that.long = arr[0];

      that.lat = arr[1];

      that.setData({

      latitude: that.lat,

      longitude: that.long})

      } else {

      wx.showToast({

      title: '没有找到相关位置',})}}})},

      //搜索确认

      searchConfirm(res) {

      var that = this;

      that.getLocation(res['detail']['value']);

      },

      doSearch(address) {

      console.log("index:" + address['name']);

      var that = this;

      if (address['type'] == "address") {

      that.getLocation(address['name']);

      } else {

      console.log('search for addr:' + address);

      console.log(address);

      var longlai = address['location'].split(",");

      that.long = longlai[0];

      that.lat = longlai[1];

      console.log('raddddddd' + circleRadius);

      that.setData({

      longitude: that.long,

      latitude: that.lat,

      searchText: address['district'] + address['address'],

      circles: [{

      latitude: that.lat,

      longitude: that.long,

      fillColor: '#7cb5ec88',

      color: '000000',

      radius: circleRadius,}]});}},})


      2019-01-22
      回复
    • 疯狂的小辣椒
      疯狂的小辣椒
      2019-01-22回复張小小

      按照教程来提供下代码片段

      2019-01-22
      回复
    • 張小小
      張小小
      2019-01-22回复疯狂的小辣椒

      https://developers.weixin.qq.com/s/waMxkBmY7W5q

      2019-01-22
      回复
登录 后发表内容