字节小程序
开发者社区
小程序小游戏
登录
抖音小程序 地图有问题 map bindregionchange 没有反应

抖音小程序 地图有问题 map bindregionchange 没有反应

1778浏览作者: 用户7508647230970

报错截图或相关BUG



复现步骤

  • <view class="container">
  •   <view class="body">
  •     <map
  •       class="maps"
  •       id="myMap"
  •       style="height:{{heights}};"
  •       latitude="{{latitude}}"
  •       longitude="{{longitude}}"
  •       markers="{{markers}}"
  •       show-location="{{true}}"
  •       show-compass
  •       enable-overlooking
  •       enable-rotate
  •       bindtap="mapTap"
  •       bindmarkertap="markerTap"
  •       bindcallouttap="calloutTap"
  •       bindregionchange="regionChange"

  •       >    </map>  </view></view>
  • Page({
  •   data: {
  •     heights:'',
  •     latitude:'28.67307',
  •     longitude: '121.44297',
  •     markers: [
  •       {
  •         id:0,
  •         latitude: 28.67307,
  •         longitude: 121.44297,
  •         title: "",
  •       },
  •     ],
  •     mapContext: null,
  •   },
  •   onLoad(){
  •     let self=this
  •     tt.getSystemInfo({
  •       success(res) {
  •         self.heights=res.screenHeight+'px'
  •         //console.log(self.heights);
  •         self.setData({
  •           heights: res.screenHeight+'px'
  •         })
  •       },
  •       fail(res) {
  •         console.log(`getSystemInfo 调用失败`);
  •       },
  •     });
  •     //console.log(tt.getStorageSync('latitude'))
  •     if(tt.getStorageSync('latitude')!=''){
  •       let latitude=tt.getStorageSync('latitude')
  •       let longitude=tt.getStorageSync('longitude')
  •       let markerss= [
  •         {
  •           id:0,
  •           latitude: latitude,
  •           longitude: longitude,
  •           title: "",
  •         },
  •       ]
  •       self.setData({
  •         markers:markerss
  •       })
  •       //console.log(markerss)
  •       //self.markers[0].latitude = latitude
  •       //self.markers[0].longitude = longitude
  •       return
  •     }
  •     tt.authorize({
  •       scope: "scope.userLocation",
  •       success() {
  •       tt.getLocation({
  •         type: 'wgs84'
  •         success: function(res) {
  •           console.log(res,'999')
  •          // self.markers[0].latitude = res.latitude
  •           //self.markers[0].longitude = res.longitude
  •           tt.setStorageSync('latitude'res.latitude)
  •           tt.setStorageSync('longitude'res.longitude)
  •           //self.loadData(res.longitude, res.latitude)    
  •          }
  •         })
  •       },
  •       fail(e){
  •         console.log(e)
  •       }
  •     })
  •   },
  •   onReady() {
  •     this.mapCtx = tt.createMapContext("myMap");
  •   },
  •   markerTap(e) {
  •     console.log("tap marker"e);
  •   },
  •   mapTap(e) {
  •     console.log("tap map"e);
  •   },
  •   calloutTap(e) {
  •     console.log("tap callout"e);
  •   },
  •   regionChange(e) {
  •     tt.showToast({
  •       title: "添加购物车成功",
  •       duration: 2000,
  •       success(res) {
  •         console.log(`${res}`);
  •       },
  •       fail(res) {
  •         console.log(`showToast 调用失败`);
  •       },
  •     });
  •     console.log("region"e);
  •   },
  •   createMapContext() {
  •     if (this.data.mapContextreturn;
  •     //API调用需传入 mapId(map 组件的 id)
  •     const mapCtx = tt.createMapContext("myMap");
  •     this.setData({
  •       mapContext: mapCtx,
  •     });
  •     console.log("地图上下文::"this.data.mapContext);
  •     mapCtx &&
  •       tt.showToast({
  •         title: "创建成功",
  •       });
  •    },
  • });
  • 所有的格式 都是 按照官方 文档 结果地图的
  •    bindregionchange="regionChange"
  • 无论 如果改动视野 一点反应都没有
最后一次编辑于 2021年12月21日
加载中