feat: 位置页面 * 2
parent
5a2f9cd8aa
commit
7f7cebf30c
6
app.json
6
app.json
|
@ -3,7 +3,6 @@
|
|||
"pages": [
|
||||
"pages/component/index/index",
|
||||
"pages/component/view/view",
|
||||
"pages/API/index/index",
|
||||
"pages/component/scroll-view/scroll-view",
|
||||
"pages/component/swiper/swiper",
|
||||
"pages/component/text/text",
|
||||
|
@ -28,6 +27,7 @@
|
|||
"pages/component/canvas/canvas",
|
||||
"pages/component/image/image",
|
||||
"pages/component/video/video",
|
||||
"pages/API/index/index",
|
||||
"pages/API/get-network-type/get-network-type",
|
||||
"pages/API/on-network-status-change/on-network-status-change",
|
||||
"pages/API/get-system-info/get-system-info",
|
||||
|
@ -52,7 +52,9 @@
|
|||
"pages/API/audio/audio",
|
||||
"pages/API/storage/storage",
|
||||
"pages/API/animation/animation",
|
||||
"pages/API/menu-info/menu-info"
|
||||
"pages/API/menu-info/menu-info",
|
||||
"pages/API/get-location/get-location",
|
||||
"pages/API/choose-location/choose-location"
|
||||
],
|
||||
"window": {
|
||||
"backgroundTextStyle": "light",
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
const util = require('../../../utils/util.js')
|
||||
|
||||
const formatLocation = util.formatLocation
|
||||
|
||||
Page({
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: '使用原生地图选择位置',
|
||||
path: 'packageAPI/pages/choose-location/choose-location'
|
||||
}
|
||||
},
|
||||
|
||||
data: {
|
||||
hasLocation: false,
|
||||
},
|
||||
chooseLocation() {
|
||||
const that = this
|
||||
wx.chooseLocation({
|
||||
success(res) {
|
||||
console.log(res)
|
||||
that.setData({
|
||||
hasLocation: true,
|
||||
location: formatLocation(res.longitude, res.latitude),
|
||||
locationAddress: res.address
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
clear() {
|
||||
this.setData({
|
||||
hasLocation: false
|
||||
})
|
||||
}
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"navigationBarTitleText": "使用原生地图选择位置"
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<import src="../../../common/head.wxml" />
|
||||
<import src="../../../common/foot.wxml" />
|
||||
|
||||
<view class="container">
|
||||
<template is="head" data="{{title: 'chooseLocation'}}"/>
|
||||
|
||||
<view class="page-body">
|
||||
<view class="page-section">
|
||||
<view class="page-body-info">
|
||||
<text class="page-body-text-small">当前位置信息</text>
|
||||
<block wx:if="{{hasLocation === false}}">
|
||||
<text class="page-body-text">未选择位置</text>
|
||||
</block>
|
||||
<block wx:if="{{hasLocation === true}}">
|
||||
<text class="page-body-text">{{locationAddress}}</text>
|
||||
<view class="page-body-text-location">
|
||||
<text>E: {{location.longitude[0]}}°{{location.longitude[1]}}′</text>
|
||||
<text>N: {{location.latitude[0]}}°{{location.latitude[1]}}′</text>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
<view class="btn-area">
|
||||
<button type="primary" bindtap="chooseLocation">选择位置</button>
|
||||
<button bindtap="clear">清空</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<template is="foot" />
|
||||
</view>
|
|
@ -0,0 +1,4 @@
|
|||
.page-body-info{
|
||||
padding-bottom: 0;
|
||||
height: 420px;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
const util = require('../../../utils/util.js')
|
||||
|
||||
const formatLocation = util.formatLocation
|
||||
|
||||
Page({
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: '获取位置',
|
||||
path: 'packageAPI/pages/get-location/get-location'
|
||||
}
|
||||
},
|
||||
|
||||
data: {
|
||||
hasLocation: false,
|
||||
},
|
||||
getLocation() {
|
||||
const that = this
|
||||
wx.getLocation({
|
||||
success(res) {
|
||||
console.log(res)
|
||||
that.setData({
|
||||
hasLocation: true,
|
||||
location: formatLocation(res.longitude, res.latitude)
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
clear() {
|
||||
this.setData({
|
||||
hasLocation: false
|
||||
})
|
||||
}
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"navigationBarTitleText": "获取位置"
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<import src="../../../common/head.wxml" />
|
||||
<import src="../../../common/foot.wxml" />
|
||||
|
||||
<view class="container">
|
||||
<template is="head" data="{{title: 'getLocation'}}"/>
|
||||
|
||||
<view class="page-body">
|
||||
<view class="page-section">
|
||||
<view class="page-body-info">
|
||||
<text class="page-body-text-small">当前位置经纬度</text>
|
||||
<block wx:if="{{hasLocation === false}}">
|
||||
<text class="page-body-text">未获取</text>
|
||||
</block>
|
||||
<block wx:if="{{hasLocation === true}}">
|
||||
<view class="page-body-text-location">
|
||||
<text>E: {{location.longitude[0]}}°{{location.longitude[1]}}′</text>
|
||||
<text>N: {{location.latitude[0]}}°{{location.latitude[1]}}′</text>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
<view class="btn-area">
|
||||
<button type="primary" bindtap="getLocation">获取位置</button>
|
||||
<button bindtap="clear">清空</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<template is="foot" />
|
||||
</view>
|
|
@ -0,0 +1,15 @@
|
|||
.page-body-info {
|
||||
height: 225px;
|
||||
}
|
||||
.page-body-text-small {
|
||||
font-size: 12px;
|
||||
color: var(--weui-FG-0);
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
.page-body-text-location {
|
||||
display: flex;
|
||||
font-size: 25px;
|
||||
}
|
||||
.page-body-text-location text {
|
||||
margin: 5px;
|
||||
}
|
|
@ -14,6 +14,80 @@ const formatNumber = n => {
|
|||
return n[1] ? n : '0' + n
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatTime: formatTime
|
||||
function formatLocation(longitude, latitude) {
|
||||
if (typeof longitude === 'string' && typeof latitude === 'string') {
|
||||
longitude = parseFloat(longitude)
|
||||
latitude = parseFloat(latitude)
|
||||
}
|
||||
|
||||
longitude = longitude.toFixed(2)
|
||||
latitude = latitude.toFixed(2)
|
||||
|
||||
return {
|
||||
longitude: longitude.toString().split('.'),
|
||||
latitude: latitude.toString().split('.')
|
||||
}
|
||||
}
|
||||
|
||||
function fib(n) {
|
||||
if (n < 1) return 0
|
||||
if (n <= 2) return 1
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
}
|
||||
|
||||
function formatLeadingZeroNumber(n, digitNum = 2) {
|
||||
n = n.toString()
|
||||
const needNum = Math.max(digitNum - n.length, 0)
|
||||
return new Array(needNum).fill(0).join('') + n
|
||||
}
|
||||
|
||||
function formatDateTime(date, withMs = false) {
|
||||
const year = date.getFullYear()
|
||||
const month = date.getMonth() + 1
|
||||
const day = date.getDate()
|
||||
const hour = date.getHours()
|
||||
const minute = date.getMinutes()
|
||||
const second = date.getSeconds()
|
||||
const ms = date.getMilliseconds()
|
||||
|
||||
let ret = [year, month, day].map(value => formatLeadingZeroNumber(value, 2)).join('-') +
|
||||
' ' + [hour, minute, second].map(value => formatLeadingZeroNumber(value, 2)).join(':')
|
||||
if (withMs) {
|
||||
ret += '.' + formatLeadingZeroNumber(ms, 3)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
function compareVersion(v1, v2) {
|
||||
v1 = v1.split('.')
|
||||
v2 = v2.split('.')
|
||||
const len = Math.max(v1.length, v2.length)
|
||||
|
||||
while (v1.length < len) {
|
||||
v1.push('0')
|
||||
}
|
||||
while (v2.length < len) {
|
||||
v2.push('0')
|
||||
}
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
const num1 = parseInt(v1[i], 10)
|
||||
const num2 = parseInt(v2[i], 10)
|
||||
|
||||
if (num1 > num2) {
|
||||
return 1
|
||||
} else if (num1 < num2) {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatTime: formatTime,
|
||||
formatLocation,
|
||||
fib,
|
||||
formatDateTime,
|
||||
compareVersion
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue