123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- // nova-werun/pages/home/sport/sport-home/index.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- //屏幕高度
- statusBarHeight: 0, // 状态栏高度
- screenHeight: 0, // 屏幕高度
- customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
- bottomNavHeight: 0, // 底部导航栏高度
- contentHeight: 0, // 可用内容高度
- contentHeight2: 0,
- contentpadding: 0, //顶部padding高度
- //
- active: 0,
- //地图
- longitude: 0,
- latitude: 0,
- markers: [],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // 计算
- const systemInfo = wx.getSystemInfoSync();
- const statusBarHeight = systemInfo.statusBarHeight || 0;
- const screenHeight = systemInfo.screenHeight || 0;
- const custom = wx.getMenuButtonBoundingClientRect();
- const customHeight = custom.height + 10 + 2 || 0;
- const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
- const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
- const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
- this.setData({
- statusBarHeight,
- screenHeight,
- customHeight,
- bottomNavHeight,
- contentpadding,
- contentHeight,
- });
- if(Number(options.id)){
- this.setData({
- active:Number(options.id)
- })
- }
- //地图
- this.Getlocation()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- //获取当前位置信息
- Getlocation() {
- // 获取当前位置信息
- wx.getLocation({
- type: 'wgs84',
- success: (res) => {
- const {
- latitude,
- longitude
- } = res;
- console.log('获取到的经纬度:', latitude, longitude); // 添加日志
- //调用api解析地址
- wx.request({
- url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
- data: {},
- header: {
- 'Content-Type': 'application/json'
- },
- success: (ops) => { // 使用箭头函数
- console.log(ops);
- const address = ops.data.result.formatted_address;
- this.setData({
- address: address,
- latitude: latitude, // 保证 latitude 被设置
- longitude: longitude, // 保证 longitude 被设置
- markers: [{ // 设置 markers
- id: 1,
- latitude: latitude,
- longitude: longitude,
- iconPath: 'https://file-cloud.fmode.cn/13WZ0W7u3l/20240724/7ebg0k104325941.png?imageView2/1/w/200/h/200', // 自定义标记图标
- width: 40,
- height: 40,
- callout: {
- content: address, // 可以显示解析出的地址
- color: '#ffffff',
- bgColor: '#7F56B2',
- padding: 10,
- borderRadius: 5,
- display: 'ALWAYS'
- }
- }]
- });
- console.log(this.data.address);
- },
- fail: function (resq) {
- wx.showModal({
- title: '信息提示',
- content: '请求失败',
- showCancel: false,
- confirmColor: '#f37938'
- });
- },
- complete: function () {}
- })
- },
- fail: (err) => {
- console.error(err);
- wx.showToast({
- title: '获取位置失败',
- icon: 'none'
- });
- }
- });
- },
- //跳转
- gourl(e) {
- const url = e.currentTarget.dataset.url
- if(this.data.active==0){
- const title='步行'
- wx.navigateTo({
- url: `${url}?id=`+title // 目标页面的路径
- });
- }else{
- const title='跑步'
- wx.navigateTo({
- url: `${url}?id=`+title // 目标页面的路径
- });
- }
- },
- })
|