日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 综合教程 >内容正文

综合教程

微信小程序中怎么实现map地图

發(fā)布時(shí)間:2023/12/19 综合教程 30 生活家
生活随笔 收集整理的這篇文章主要介紹了 微信小程序中怎么实现map地图 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這篇“微信小程序中怎么實(shí)現(xiàn)map地圖”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“微信小程序中怎么實(shí)現(xiàn)map地圖”文章吧。

前言

微信小程序地圖操作比較簡(jiǎn)單,api也很少,使用map組件來展示。說到地圖,那就先來看基礎(chǔ)定位:

定位用到wx.getLocation(OBJECT)函數(shù),代碼如下:

wx.getLocation({
type:'wgs84',
success:function(res){
varlatitude=res.latitude
varlongitude=res.longitude
varspeed=res.speed
varaccuracy=res.accuracy
}
})

定位成功會(huì)返回四個(gè)參數(shù)值,如下:

map屬性太多,先看一下:

如果用到地圖,基本上所有屬性都會(huì)用到。

下面一一看一下,我們先看效果圖吧,先看真相:

這里我只用了一個(gè)markers,就是定位當(dāng)前位置的紅色markers,用法如下:

wx.getLocation({
type:'wgs84',//默認(rèn)為wgs84返回gps坐標(biāo),gcj02返回可用于wx.openLocation的坐標(biāo)
success:function(res){

_this.setData({
latitude:res.latitude,
longitude:res.longitude,
markers:[{
id:"1",
latitude:res.latitude,
longitude:res.longitude,
width:50,
height:50,
iconPath:"/assests/imgs/my.png",
title:"哪里"

}],
circles:[{
latitude:res.latitude,
longitude:res.longitude,
color:'#FF0000DD',
fillColor:'#7cb5ec88',
radius:3000,
strokeWidth:1
}]

})
}

})

這里加了circles,半徑是3000米,具體的api可自行看官網(wǎng)。

接下來看看controls,控制層,在地圖上顯示控件,控件不隨著地圖移動(dòng),看API:

注意看示例圖的右上角,有兩個(gè)按鈕,加減號(hào),是控制地圖scale的數(shù)值變化,動(dòng)態(tài)縮放地圖的,controls用法也很簡(jiǎn)單:

controls:[{
id:1,
iconPath:'/assests/imgs/jian.png',
position:{
left:320,
top:100-50,
width:20,
height:20
},
clickable:true
},
{
id:2,
iconPath:'/assests/imgs/jia.png',
position:{
left:340,
top:100-50,
width:20,
height:20
},
clickable:true
}
]

最后我們看一張gif圖:

最后上一下具體代碼:

wxml:

<mapid="map"longitude="{{longitude}}"latitude="{{latitude}}"scale="{{scale}}"controls="{{controls}}"bindcontroltap="controltap"markers="{{markers}}"circles="{{circles}}"bindmarkertap="markertap"polyline="{{polyline}}"bindregionchange="regionchange"show-location></map>

js:

Page({
data:{
Height:0,
scale:13,
latitude:"",
longitude:"",
markers:[],
controls:[{
id:1,
iconPath:'/assests/imgs/jian.png',
position:{
left:320,
top:100-50,
width:20,
height:20
},
clickable:true
},
{
id:2,
iconPath:'/assests/imgs/jia.png',
position:{
left:340,
top:100-50,
width:20,
height:20
},
clickable:true
}
],
circles:[]

},

onLoad:function(){
var_this=this;

wx.getSystemInfo({
success:function(res){
//設(shè)置map高度,根據(jù)當(dāng)前設(shè)備寬高滿屏顯示
_this.setData({
view:{
Height:res.windowHeight
}

})



}
})

wx.getLocation({
type:'wgs84',//默認(rèn)為wgs84返回gps坐標(biāo),gcj02返回可用于wx.openLocation的坐標(biāo)
success:function(res){

_this.setData({
latitude:res.latitude,
longitude:res.longitude,
markers:[{
id:"1",
latitude:res.latitude,
longitude:res.longitude,
width:50,
height:50,
iconPath:"/assests/imgs/my.png",
title:"哪里"

}],
circles:[{
latitude:res.latitude,
longitude:res.longitude,
color:'#FF0000DD',
fillColor:'#7cb5ec88',
radius:3000,
strokeWidth:1
}]

})
}

})

},

regionchange(e){
console.log("regionchange==="+e.type)
},

//點(diǎn)擊merkers
markertap(e){
console.log(e.markerId)

wx.showActionSheet({
itemList:["A"],
success:function(res){
console.log(res.tapIndex)
},
fail:function(res){
console.log(res.errMsg)
}
})
},

//點(diǎn)擊縮放按鈕動(dòng)態(tài)請(qǐng)求數(shù)據(jù)
controltap(e){
varthat=this;
console.log("scale==="+this.data.scale)
if(e.controlId===1){
//if(this.data.scale===13){
that.setData({
scale:--this.data.scale
})
//}
}else{
//if(this.data.scale!==13){
that.setData({
scale:++this.data.scale
})
//}
}


},


})

總結(jié)

以上是生活随笔為你收集整理的微信小程序中怎么实现map地图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。