最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序 開發(fā)MAP(地圖)實例詳解

 更新時間:2017年06月27日 09:56:01   投稿:lqh  
這篇文章主要介紹了微信小程序 開發(fā)MAP(地圖)實例詳解的相關(guān)資料,需要的朋友可以參考下

微信小程序 開發(fā)MAP(地圖)實例詳解

在創(chuàng)建MAP(地圖)前,請各位小伙伴們認真的去了解微信小程序開發(fā)的說明。

https://mp.weixin.qq.com/debug/wxadoc/dev/component/map.html#map

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

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

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

第二步:我們來寫 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文件的代碼寫好之后,就要來進行第三步了。

第三步:寫 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)示出來
 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
 // 動態(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
   }]
  })
  }
 })
 }
 //獲取中間點的經(jīng)緯度,并mark出來
 , 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ā)生變化的時候,獲取中間點,也就是用戶選擇的位置
 if (e.type == 'end') {
  this.getLngLat()
 }
 }
 , markertap(e) {
 console.log(e)
 }
})

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

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

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

平湖市| 乌恰县| 望奎县| 信阳市| 甘肃省| 迁安市| 连南| 郯城县| 思茅市| 苏尼特右旗| 马尔康县| 博客| 集安市| 咸阳市| 高雄县| 巴彦淖尔市| 柳州市| 太湖县| 肥西县| 杭锦旗| 徐水县| 策勒县| 桂林市| 武汉市| 静乐县| 宣汉县| 海林市| 徐汇区| 顺义区| 和政县| 岳阳市| 通道| 鄄城县| 苗栗县| 舒城县| 聂荣县| 阳信县| 富源县| 安新县| 涟水县| 晋江市|