免费国产欧美国日产_少妇AV一区二区三区无码_蜜桃精品av无码喷奶水小说_jk18禁网站视频_精产国品一二三级产品区别_被夫の上司に犯波多野结衣_78m成人手机免费看_最爽最刺激18禁视频_偷偷色噜狠狠狠狠的777米奇

易優(yōu)GEO 重磅上線 ~ 一站式GEO優(yōu)化工具,讓豆包、文心一言、DeepSeek 在回答中主動(dòng)推薦你的品牌,搶占AI流量入口!  點(diǎn)擊查看

小程序模板網(wǎng)

微信小程序開(kāi)發(fā)MAP(地圖)

發(fā)布時(shí)間:2017-12-21 10:02 所屬欄目:小程序開(kāi)發(fā)教程

在創(chuàng)建MAP(地圖)前,請(qǐng)各位小伙伴們認(rèn)真的去了解微信小程序開(kāi)發(fā)的說(shuō)明。https://mp.weixin.qq.com/debug/wxadoc/dev/component/map.html#map了解完MAP(地圖)里的屬性之后,接下來(lái)我們就來(lái)創(chuàng)建一個(gè)簡(jiǎn)單的MAP(地 ...

 
 
 

在創(chuàng)建MAP(地圖)前,請(qǐng)各位小伙伴們認(rèn)真的去了解微信小程序開(kāi)發(fā)的說(shuō)明。https://mp.weixin.qq.com/debug/wxadoc/dev/component/map.html#map

了解完MAP(地圖)里的屬性之后,接下來(lái)我們就來(lái)創(chuàng)建一個(gè)簡(jiǎn)單的MAP(地圖)控件。

第一步:肯定是創(chuàng)建項(xiàng)目、起項(xiàng)目名、項(xiàng)目地址

PS:我這里以index的文件為名

第二步:我們來(lái)寫(xiě) index.wxml 文件的代碼

WXML文件代碼:

<map id="map4select" longitude="{{longitude}}" latitude="{{latitude}}" markers="{{markers}}" scale="20" style="width:{{map_width}}px;height:{{map_height}}px" bindregionchange="regionchange" controls="{{controls}}">
 </map>

WXML文件的代碼寫(xiě)好之后,就要來(lái)進(jìn)行第三步了。

第三步:寫(xiě) index.js 文件的代碼

var app = getApp()

Page({
  data: {
    map_width: 380
    , map_height: 380
  }
  //show current position
  , onLoad: function (options) {
    console.log(options.schedule_id);
    var that = this;
    // 獲取定位,并把位置標(biāo)示出來(lái)
    that.setData({
      longitude: 113.324520
      , latitude: 23.099994
      , markers: [
        {
          id: 0
          , iconPath: "../imgs/ic_position.png"
          , longitude: 113.324520
          , latitude: 23.099994
          , width: 30
          , height: 30
        }
      ]
    })
    //set the width and height
    // 動(dòng)態(tài)設(shè)置map的寬和高
    wx.getSystemInfo({
      success: function (res) {
        console.log(res.windowWidth);
        that.setData({
          map_width: res.windowWidth
          , map_height: res.windowWidth
          , controls: [{
            id: 1,
            iconPath: '../imgs/ic_location.png',
            position: {
              left: res.windowWidth / 2 - 8  ,
              top: res.windowWidth / 2 - 16 ,
              width: 30,
              height: 30 
            },
            clickable: true
          }]
        })
      }
    })
  }
  //獲取中間點(diǎn)的經(jīng)緯度,并mark出來(lái)
  , getLngLat: function () {
    var that = this;
    this.mapCtx = wx.createMapContext("map4select");
    this.mapCtx.getCenterLocation({
      success: function (res) {
        that.setData({
          longitude: 113.324520
          , latitude: 23.099994
          , markers: [
            {
              id: 0
              , iconPath: "../imgs/ic_position.png"
              , longitude: 113.324520
              , latitude: 23.099994
              , width: 30
              , height: 30
            }
          ]
        })
      }
    })
  }
  , regionchange(e) {
    // 地圖發(fā)生變化的時(shí)候,獲取中間點(diǎn),也就是用戶選擇的位置
    if (e.type == 'end') {
      this.getLngLat()
    }
  }
  , markertap(e) {
    console.log(e)
  }
})

index.js 和 index.wxml 兩個(gè)文件的代碼已經(jīng)寫(xiě)好,那么我們就來(lái)頁(yè)面上看看效果。

PS:“../imgs/ic_position.png” 和 “../imgs/ic_location.png” 是我在項(xiàng)目里創(chuàng)建的一個(gè)名叫imgs文件夾里面的兩個(gè)定位小圖標(biāo),各位小伙伴們可以根據(jù)自己的需求改換小圖標(biāo),只需要把小圖標(biāo)放進(jìn)imgs文件夾里面,小圖標(biāo)的路徑引用正確就可以顯示出來(lái)。



易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://m.szcjxy.com/wxmini/doc/course/18215.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢: 點(diǎn)擊咨詢
在線客服