One, create a map page
Location
Second, the content of the map page
1. No need to write Location.wxml
2,Location.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
longitude:0,//中心经度
latitude:0,//中心纬度
name:""//选择的位置名称
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.moveToLocation()
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
moveToLocation:function(){
var that=this;
wx.chooseLocation({
success:res=>{
console.log(res)
let place=res.name
wx.navigateTo({
url: '/pages/task/task?place='+place,
})
},
fail:err=>{
console.log(err)
}
})
},
})
Three, call to get the map location
1. Click to get the location on the task.js page
2. It will jump to the map page defined just now, then select the current location, and then pass it to the task page
3. Call the page content
task.wxml
<view bindtap="getLocationPlace">
点击获取位置
</view>
task.js
onLoad: function (options) {
console.log(options.place)//获取到Location页面传过来的位置名称
},
getLocationPlace(){
wx.navigateTo({
url: '/pages/Location/Location',
})
}