微信小程序微信小程序 开发开发MAP(地图)实例详解(地图)实例详解
主要介绍了微信小程序 开发MAP(地图)实例详解的相关资料,需要的朋友可以参考下
微信小程序微信小程序 开发开发MAP(地图)实例详解(地图)实例详解
在创建MAP(地图)前,请各位小伙伴们认真的去了解微信小程序开发的说明。
https://mp.weixin.qq.com/debug/wxadoc/dev/component/map.html#map
了解完MAP(地图)里的属性之后,接下来我们就来创建一个简单的MAP(地图)控件。
第一步:肯定是创建项目、起项目名、项目地址第一步:肯定是创建项目、起项目名、项目地址
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;
// 获取定位,并把位置标示出来
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
// 动态设置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
}]
})
}