Kaynağa Gözat

地图maker

elis 2 yıl önce
ebeveyn
işleme
f7f0c9e9cf
2 değiştirilmiş dosya ile 38 ekleme ve 20 silme
  1. 37 19
      nnzwminiapp/pages/map/map.js
  2. 1 1
      nnzwminiapp/pages/map/map.wxml

+ 37 - 19
nnzwminiapp/pages/map/map.js

@@ -40,10 +40,23 @@ const popType = [
         []
     ]
 ]
+
+const INIT_MARKER = {
+	latitude: 0,
+	longitude: 0,
+	iconPath: imgUrl+"/location.png",
+	width: '34px',
+	height: '34px',
+	rotate: 0,
+	alpha: 1
+};
+
+
+
 Page({
     data: {
         imgUrl: imgUrl,
-        markers: [],
+        markers: [INIT_MARKER],
         latitude: '',
         longitude: '',
         type: [
@@ -75,34 +88,39 @@ Page({
 
     onLoad: function () {
         var that = this;
-        var BMap = new bmap.BMapWX({
-            ak: 'QCc4aj8erQKVSfREHsbOLEDu3htQrNQU'
-        });
+        // var BMap = new bmap.BMapWX({
+        //     ak: 'QCc4aj8erQKVSfREHsbOLEDu3htQrNQU'
+        // });
 
         var fail = function (data) {
             console.log(data)
         };
         var success = function (data) {
             wxMarkerData = data.wxMarkerData;
-            that.setData({
-                markers: wxMarkerData
-            });
-            that.setData({
-                latitude: wxMarkerData[0].latitude
-            });
-            that.setData({
-                longitude: wxMarkerData[0].longitude
-            });
         }
         this.setData({
             height: wx.getSystemInfoSync().windowHeight
         })
-        BMap.geocoding({
-            address: '重庆市',
-            fail: fail,
-            success: success
-        });
-
+        wx.getLocation({
+          type: 'gcj02', //返回可以用于wx.openLocation的经纬度
+          success (res) {
+            const latitude = res.latitude
+            const longitude = res.longitude
+            that.setData({
+              latitude: latitude,
+              longitude:longitude,
+              markers:[{
+                latitude: latitude,
+                longitude: longitude,
+                iconPath: imgUrl+"/location.png",
+                width: '34px',
+                height: '34px',
+                rotate: 0,
+                alpha: 1
+              }]
+            });
+          }
+         })
         // 初始化数据
         wx.request({
             url: 'https://www.cqna.gov.cn/data/mapdata/getMapDataAll',

+ 1 - 1
nnzwminiapp/pages/map/map.wxml

@@ -30,7 +30,7 @@
     </view>
 
     <view class="right-map" id="right-map">
-      <map id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="14" show-location="true" markers="{{markers}}" bindmarkertap="makertap" class="map"></map>
+      <map id="map" longitude="{{longitude}}"  latitude="{{latitude}}" scale="18" show-location="true" bindmarkertap="makertap"  markers="{{markers}}" class="map"></map>
     </view>
 
     <view wx:if="{{showTraffic}}">