diff --git a/app.json b/app.json
index d0b9bd5..b509642 100644
--- a/app.json
+++ b/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",
diff --git a/pages/API/choose-location/choose-location.js b/pages/API/choose-location/choose-location.js
new file mode 100644
index 0000000..0ec2173
--- /dev/null
+++ b/pages/API/choose-location/choose-location.js
@@ -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
+ })
+ }
+})
diff --git a/pages/API/choose-location/choose-location.json b/pages/API/choose-location/choose-location.json
new file mode 100644
index 0000000..485fbc1
--- /dev/null
+++ b/pages/API/choose-location/choose-location.json
@@ -0,0 +1,3 @@
+{
+ "navigationBarTitleText": "使用原生地图选择位置"
+}
\ No newline at end of file
diff --git a/pages/API/choose-location/choose-location.wxml b/pages/API/choose-location/choose-location.wxml
new file mode 100644
index 0000000..af41f7f
--- /dev/null
+++ b/pages/API/choose-location/choose-location.wxml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+ 当前位置信息
+
+ 未选择位置
+
+
+ {{locationAddress}}
+
+ E: {{location.longitude[0]}}°{{location.longitude[1]}}′
+ N: {{location.latitude[0]}}°{{location.latitude[1]}}′
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pages/API/choose-location/choose-location.wxss b/pages/API/choose-location/choose-location.wxss
new file mode 100644
index 0000000..0febcd6
--- /dev/null
+++ b/pages/API/choose-location/choose-location.wxss
@@ -0,0 +1,4 @@
+.page-body-info{
+ padding-bottom: 0;
+ height: 420px;
+}
\ No newline at end of file
diff --git a/pages/API/get-location/get-location.js b/pages/API/get-location/get-location.js
new file mode 100644
index 0000000..be10a25
--- /dev/null
+++ b/pages/API/get-location/get-location.js
@@ -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
+ })
+ }
+})
diff --git a/pages/API/get-location/get-location.json b/pages/API/get-location/get-location.json
new file mode 100644
index 0000000..480f5d3
--- /dev/null
+++ b/pages/API/get-location/get-location.json
@@ -0,0 +1,3 @@
+{
+ "navigationBarTitleText": "获取位置"
+}
diff --git a/pages/API/get-location/get-location.wxml b/pages/API/get-location/get-location.wxml
new file mode 100644
index 0000000..f38bc3c
--- /dev/null
+++ b/pages/API/get-location/get-location.wxml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+ 当前位置经纬度
+
+ 未获取
+
+
+
+ E: {{location.longitude[0]}}°{{location.longitude[1]}}′
+ N: {{location.latitude[0]}}°{{location.latitude[1]}}′
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pages/API/get-location/get-location.wxss b/pages/API/get-location/get-location.wxss
new file mode 100644
index 0000000..0b64b81
--- /dev/null
+++ b/pages/API/get-location/get-location.wxss
@@ -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;
+}
diff --git a/utils/util.js b/utils/util.js
index dbadbb8..bc1e5e0 100644
--- a/utils/util.js
+++ b/utils/util.js
@@ -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
}