Blame view

pages/API/map-search/map-search.nvue 2.86 KB
4b045f7c   刘淇   江阴初始化项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  <template>
      <view class="content">
          <map class="map" ref="dcmap" :markers="markers" @tap="selectPoint"></map>
          <scroll-view class="scrollview" scroll-y="true">
              <button class="button" @click="reverseGeocode">reverseGeocode</button>
              <button class="button" @click="poiSearchNearBy">poiSearchNearBy</button>
          </scroll-view>
      </view>
  </template>
  
  <script>
      // 116.397477,39.908692
      let mapSearch = weex.requireModule('mapSearch')
      export default {
          data() {
              return {
                  markers: [{
                      id: '1',
                      latitude: 39.9086920000,
                      longitude: 116.3974770000,
                      title: '天安门',
                      zIndex: '1',
                      iconPath: '/static/gps.png',
                      width: 20,
                      height: 20,
                      anchor: {
                          x: 0.5,
                          y: 1
                      },
                      callout: {
                          content: '首都北京\n天安门',
                          color: '#00BFFF',
                          fontSize: 12,
                          borderRadius: 2,
                          borderWidth: 0,
                          borderColor: '#333300',
                          bgColor: '#CCFF11',
                          padding: '1',
                          display: 'ALWAYS'
                      }
                  }]
              }
          },
          methods: {
              selectPoint(e) {
                  console.log(e);
              },
              reverseGeocode() {
                  var point = this.markers[0]
                  mapSearch.reverseGeocode({
                      point: {
                          latitude: point.latitude,
                          longitude: point.longitude
                      }
                  }, ret => {
                      console.log(JSON.stringify(ret));
                      uni.showModal({
                          content: JSON.stringify(ret)
                      })
                  })
              },
              poiSearchNearBy() {
                  var point = this.markers[0]
                  mapSearch.poiSearchNearBy({
                      point: {
                          latitude: point.latitude,
                          longitude: point.longitude
                      },
                      key: '停车场',
                      radius: 1000
                  }, ret => {
                      console.log(ret);
                      uni.showModal({
                          content: JSON.stringify(ret)
                      })
                  })
  
              }
          }
      }
  </script>
  
  <style>
      .content {
          flex: 1;
      }
  
      .map {
          width: 750rpx;
          height: 500rpx;
          background-color: black;
      }
  
      .scrollview {
          flex: 1;
      }
  
      .button {
          margin-top: 30rpx;
          margin-bottom: 20rpx;
      }
  </style>