微信小程序开发中怎样使用Map对象
//index.js
//获取应用实例
const 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: "/images/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: '/images/location.png',
position: {
left: res.windowWidth / 2 - 8,
top: res.windowWidth / 2 - 16,
width: 30,
height: 30
},
clickable: true
}]
})
}
})
}
//获取中间点的经纬度,并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: "/imgages/position.png"
, longitude: 113.324520
, latitude: 23.099994
, width: 30
, height: 30
}
]
})
}
})
}
// , regionchange(e) {
// // 地图发生变化的时候,获取中间点,也就是用户选择的位置
// if (e.type == 'end') {
// this.getLngLat()
// }
// }
// , markertap(e) {
// console.log(e)
// }
})
// Page({
// data: {
// latitude: 0,//纬度
// longitude: 0,//经度
// speed: 0,//速度
// accuracy: 16,//位置精准度
// markers: [],
// covers: [],
// },
// onLoad: function () {
// },
// getlocation: function () {
// wx.getLocation({
// type: 'gcj02',
// success: function (res) {
// var latitude = res.latitude
// var longitude = res.longitude
// var speed = res.speed
// var accuracy = res.accuracy
// console.log("latitude:" + latitude)
// console.log("longitude:" + longitude)
// console.log("speed:" + speed)
// console.log("accuracy:" + accuracy)
// wx.openLocation({
// latitude: latitude,
// longitude: longitude,
// scale: 28
// })
// }
// })
// }
// })