init
This commit is contained in:
200
xhs-mini-demos/api-case/get-location/get-location.js
Normal file
200
xhs-mini-demos/api-case/get-location/get-location.js
Normal file
@@ -0,0 +1,200 @@
|
||||
const __templateJs = require("./templates.js");
|
||||
const __mergePageOptions = require("../../util/mergePageOptions.js");
|
||||
Page(__mergePageOptions({
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: '获取位置',
|
||||
path: 'packageAPI/pages/get-location/get-location'
|
||||
};
|
||||
},
|
||||
data: {
|
||||
count: 0,
|
||||
hasLocation: false,
|
||||
altitude: false,
|
||||
isHighAccuracy: false,
|
||||
highAccuracyExpireTime: 0,
|
||||
latitude: 12.1,
|
||||
longitude: 12.1,
|
||||
type: 'wgs84',
|
||||
apiData: {
|
||||
content: '',
|
||||
success: false,
|
||||
fail: false,
|
||||
complete: false
|
||||
},
|
||||
choosedLocation: {
|
||||
name: '',
|
||||
address: '',
|
||||
latitude: '',
|
||||
longitude: ''
|
||||
},
|
||||
getLoaction: {
|
||||
accuracy: '',
|
||||
altitude: '',
|
||||
horizontalAccuracy: '',
|
||||
latitude: '',
|
||||
longitude: '',
|
||||
speed: '',
|
||||
verticalAccuracy: ''
|
||||
}
|
||||
},
|
||||
resetApiData() {
|
||||
this.setData({
|
||||
apiData: {
|
||||
success: false,
|
||||
fail: false,
|
||||
complete: false,
|
||||
content: ''
|
||||
}
|
||||
});
|
||||
},
|
||||
updateApiData(type, content) {
|
||||
const apiData = {
|
||||
...this.data.apiData
|
||||
};
|
||||
apiData[type] = true;
|
||||
apiData.content = content;
|
||||
this.setData({
|
||||
apiData
|
||||
});
|
||||
},
|
||||
getLocation() {
|
||||
this.resetApiData();
|
||||
xhs.getLocation({
|
||||
success: res => {
|
||||
this.setData({
|
||||
getLoaction: res
|
||||
});
|
||||
console.log('getlocation', res);
|
||||
},
|
||||
fail: res => {
|
||||
this.updateApiData('fail', res);
|
||||
},
|
||||
complete: res => {
|
||||
this.updateApiData('complete', res);
|
||||
}
|
||||
});
|
||||
},
|
||||
startLocationUpdate() {
|
||||
this.resetApiData();
|
||||
xhs.startLocationUpdate({
|
||||
success: res => {
|
||||
this.updateApiData('success', res);
|
||||
xhs.showToast({
|
||||
title: '已开启位置服务'
|
||||
});
|
||||
},
|
||||
fail: res => {
|
||||
this.updateApiData('fail', res);
|
||||
},
|
||||
complete: res => {
|
||||
this.updateApiData('complete', res);
|
||||
}
|
||||
});
|
||||
},
|
||||
startLocationUpdateBackground() {
|
||||
this.resetApiData();
|
||||
xhs.startLocationUpdateBackground({
|
||||
success: res => {
|
||||
this.updateApiData('success', res);
|
||||
},
|
||||
fail: res => {
|
||||
this.updateApiData('fail', res);
|
||||
},
|
||||
complete: res => {
|
||||
this.updateApiData('complete', res);
|
||||
}
|
||||
});
|
||||
},
|
||||
stopLocationUpdate() {
|
||||
this.resetApiData();
|
||||
xhs.stopLocationUpdate({
|
||||
success: res => {
|
||||
this.updateApiData('success', res);
|
||||
xhs.showToast({
|
||||
title: '已关闭位置服务'
|
||||
});
|
||||
},
|
||||
fail: res => {
|
||||
this.updateApiData('fail', res);
|
||||
},
|
||||
complete: res => {
|
||||
this.updateApiData('complete', res);
|
||||
}
|
||||
});
|
||||
},
|
||||
chooseLocation() {
|
||||
this.resetApiData();
|
||||
xhs.chooseLocation({
|
||||
latitude: this.data.latitude - 0,
|
||||
longitude: this.data.longitude - 0,
|
||||
success: res => {
|
||||
this.setData({
|
||||
choosedLocation: res
|
||||
});
|
||||
},
|
||||
fail: res => {
|
||||
this.updateApiData('fail', res);
|
||||
},
|
||||
complete: res => {
|
||||
this.updateApiData('complete', res);
|
||||
}
|
||||
});
|
||||
},
|
||||
onLocationChange() {
|
||||
this.resetApiData();
|
||||
this.offLocation = xhs.onLocationChange(res => {
|
||||
this.updateApiData('success', res);
|
||||
this.setData({
|
||||
count: this.data.count + 1
|
||||
});
|
||||
});
|
||||
},
|
||||
offLocationChange() {
|
||||
if (this?.offLocation?.remove) {
|
||||
this.offLocation.remove();
|
||||
}
|
||||
this.updateApiData('success');
|
||||
},
|
||||
handleAltitude(e) {
|
||||
this.setData({
|
||||
altitude: e.detail.value
|
||||
});
|
||||
},
|
||||
handleHighAccuracy(e) {
|
||||
this.setData({
|
||||
isHighAccuracy: e.detail.value
|
||||
});
|
||||
},
|
||||
handleHighAccuracyExpireTime(e) {
|
||||
this.setData({
|
||||
highAccuracyExpireTime: e.detail.value - 0
|
||||
});
|
||||
},
|
||||
handleType(e) {
|
||||
this.setData({
|
||||
type: e.detail.value
|
||||
});
|
||||
},
|
||||
handleLongitude(e) {
|
||||
this.setData({
|
||||
longitude: e.detail.value - 0
|
||||
});
|
||||
},
|
||||
handleLatitude(e) {
|
||||
this.setData({
|
||||
latitude: e.detail.value - 0
|
||||
});
|
||||
},
|
||||
openLocation() {
|
||||
xhs.openLocation({
|
||||
latitude: 31.215442551782044,
|
||||
longitude: 121.47457688571865,
|
||||
address: '上海市黄浦区马当路356号',
|
||||
name: '小红书总部',
|
||||
complete: res => {
|
||||
console.log('【openLocation】:', res);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, __templateJs));
|
||||
8
xhs-mini-demos/api-case/get-location/get-location.json
Normal file
8
xhs-mini-demos/api-case/get-location/get-location.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"navigationBarTitleText": "获取位置",
|
||||
"usingComponents": {
|
||||
"showbox": "../../common/component/showbox/index",
|
||||
"box": "../../common/component/container/index",
|
||||
"api-status": "../../common/component/api-status/index"
|
||||
}
|
||||
}
|
||||
57
xhs-mini-demos/api-case/get-location/get-location.xhsml
Normal file
57
xhs-mini-demos/api-case/get-location/get-location.xhsml
Normal file
@@ -0,0 +1,57 @@
|
||||
<view class="container">
|
||||
<showbox title="选择位置">
|
||||
<box>
|
||||
<view class="_ui-space">
|
||||
<view>名称:{{choosedLocation.name}}</view>
|
||||
<view>地址:{{choosedLocation.address}}</view>
|
||||
<view>经度:{{choosedLocation.latitude}}</view>
|
||||
<view>纬度:{{choosedLocation.longitude}}</view>
|
||||
<!-- <view class="_ui-input _my8">
|
||||
<input type="text" value="{{latitude}}" bindinput="handleLatitude" />
|
||||
</view>
|
||||
<view class="_ui-input _mb8">
|
||||
<input type="text" value="{{longitude}}" bindinput="handleLongitude" />
|
||||
</view> -->
|
||||
|
||||
<button class="_ui-button" hover-class="_ui-button-hover" bindtap="chooseLocation">选择位置</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="获取当前位置">
|
||||
<box>
|
||||
<view class="_ui-space">
|
||||
<view>纬度:{{getLoaction.latitude}}</view>
|
||||
<view>经度:{{getLoaction.longitude}}</view>
|
||||
<view>速度:{{getLoaction.speed}}</view>
|
||||
<view>位置的精确度:{{getLoaction.accuracy}}</view>
|
||||
|
||||
<view>高度:{{getLoaction.altitude}}</view>
|
||||
<view>垂直精度:{{getLoaction.verticalAccuracy}}</view>
|
||||
<view>水平精度:{{getLoaction.horizontalAccuracy}}</view>
|
||||
|
||||
<button class="_ui-button" hover-class="_ui-button-hover" bindtap="getLocation">获取当前位置</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="使用内置地图">
|
||||
<box>
|
||||
<view class="_ui-space">
|
||||
<button class="_ui-button" hover-class="_ui-button-hover" bindtap="openLocation">使用内置地图查看</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="实时获取位置">
|
||||
<box>
|
||||
<view class="_ui-space">
|
||||
<button class="_ui-button" hover-class="_ui-button-hover" bindtap="startLocationUpdate">开启接受位置消息</button>
|
||||
<button class="_ui-button" hover-class="_ui-button-hover" bindtap="stopLocationUpdate">关闭接受位置消息</button>
|
||||
<!-- <button class="_ui-button" hover-class="_ui-button-hover" bindtap="onLocationChange">绑定监控位置事件</button>
|
||||
<button class="_ui-button" hover-class="_ui-button-hover" bindtap="offLocationChange">取消监控位置事件</button> -->
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
</view>
|
||||
<include src="templates.xhsml" />
|
||||
295
xhs-mini-demos/api-case/get-location/templates.js
Normal file
295
xhs-mini-demos/api-case/get-location/templates.js
Normal file
@@ -0,0 +1,295 @@
|
||||
/** 以下内容为自动生成,请勿手动修改 */
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
page_data_0: "",
|
||||
|
||||
page_data_1: false,
|
||||
|
||||
page_data_2: false,
|
||||
|
||||
page_data_3: false,
|
||||
|
||||
page_data_4: "",
|
||||
|
||||
page_data_5: false,
|
||||
|
||||
page_data_6: false,
|
||||
|
||||
page_data_7: false,
|
||||
|
||||
page_data_8: "",
|
||||
|
||||
page_data_9: false,
|
||||
|
||||
page_data_10: false,
|
||||
|
||||
page_data_11: false,
|
||||
|
||||
page_data_12: "",
|
||||
|
||||
page_data_13: false,
|
||||
|
||||
page_data_14: false,
|
||||
|
||||
page_data_15: false,
|
||||
|
||||
page_data_16: "",
|
||||
|
||||
page_data_17: "",
|
||||
|
||||
page_data_18: "",
|
||||
|
||||
page_data_19: false,
|
||||
|
||||
page_data_20: false,
|
||||
|
||||
page_data_21: false,
|
||||
|
||||
page_data_22: "",
|
||||
|
||||
page_data_23: "",
|
||||
|
||||
page_data_24: "",
|
||||
|
||||
page_data_25: "",
|
||||
|
||||
page_data_26: "",
|
||||
|
||||
page_data_27: "",
|
||||
|
||||
page_data_28: false,
|
||||
|
||||
page_data_29: false,
|
||||
|
||||
page_data_30: false,
|
||||
|
||||
page_data_31: "",
|
||||
},
|
||||
|
||||
page_fun_1(e) {
|
||||
this.setData("page_data_0", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_0() {
|
||||
this.setData({
|
||||
page_data_1: false,
|
||||
page_data_2: false,
|
||||
page_data_3: false,
|
||||
});
|
||||
|
||||
xhs.getLocation({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_1: true,
|
||||
page_data_4: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_2: true,
|
||||
page_data_4: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_3: true,
|
||||
});
|
||||
},
|
||||
type: this.data.page_data_0,
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_2() {
|
||||
this.setData({
|
||||
page_data_5: false,
|
||||
page_data_6: false,
|
||||
page_data_7: false,
|
||||
});
|
||||
|
||||
xhs.startLocationUpdate({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_5: true,
|
||||
page_data_8: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_6: true,
|
||||
page_data_8: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_7: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_3() {
|
||||
this.setData({
|
||||
page_data_9: false,
|
||||
page_data_10: false,
|
||||
page_data_11: false,
|
||||
});
|
||||
|
||||
xhs.startLocationUpdateBackground({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_9: true,
|
||||
page_data_12: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_10: true,
|
||||
page_data_12: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_11: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_4() {
|
||||
this.setData({
|
||||
page_data_13: false,
|
||||
page_data_14: false,
|
||||
page_data_15: false,
|
||||
});
|
||||
|
||||
xhs.stopLocationUpdate({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_13: true,
|
||||
page_data_16: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_14: true,
|
||||
page_data_16: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_15: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_6(e) {
|
||||
this.setData("page_data_17", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_7(e) {
|
||||
this.setData("page_data_18", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_5() {
|
||||
this.setData({
|
||||
page_data_19: false,
|
||||
page_data_20: false,
|
||||
page_data_21: false,
|
||||
});
|
||||
|
||||
xhs.chooseLocation({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_19: true,
|
||||
page_data_22: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_20: true,
|
||||
page_data_22: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_21: true,
|
||||
});
|
||||
},
|
||||
latitude: this.data.page_data_17,
|
||||
longitude: this.data.page_data_18,
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_9(e) {
|
||||
this.setData("page_data_23", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_10(e) {
|
||||
this.setData("page_data_24", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_11(e) {
|
||||
this.setData("page_data_25", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_12(e) {
|
||||
this.setData("page_data_26", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_13(e) {
|
||||
this.setData("page_data_27", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_8() {
|
||||
this.setData({
|
||||
page_data_28: false,
|
||||
page_data_29: false,
|
||||
page_data_30: false,
|
||||
});
|
||||
|
||||
xhs.openLocation({
|
||||
success: (res) => {
|
||||
console.log("success", res);
|
||||
this.setData({
|
||||
page_data_28: true,
|
||||
page_data_31: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("fail", res);
|
||||
this.setData({
|
||||
page_data_29: true,
|
||||
page_data_31: JSON.stringify(res),
|
||||
});
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log("complete", res);
|
||||
this.setData({
|
||||
page_data_30: true,
|
||||
});
|
||||
},
|
||||
latitude: this.data.page_data_23,
|
||||
longitude: this.data.page_data_24,
|
||||
scale: this.data.page_data_25,
|
||||
name: this.data.page_data_26,
|
||||
address: this.data.page_data_27,
|
||||
});
|
||||
},
|
||||
};
|
||||
161
xhs-mini-demos/api-case/get-location/templates.xhsml
Normal file
161
xhs-mini-demos/api-case/get-location/templates.xhsml
Normal file
@@ -0,0 +1,161 @@
|
||||
<!-- 以下内容为自动生成,请勿手动修改 -->
|
||||
|
||||
<view class="container">
|
||||
<showbox title="getLocation演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_1}}"
|
||||
complete="{{page_data_3}}"
|
||||
fail="{{page_data_2}}"
|
||||
text="{{page_data_4}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<view class="_ui-input">
|
||||
<input placeholder="type" type="text" bindinput="page_fun_1" />
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_0"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="startLocationUpdate演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_5}}"
|
||||
complete="{{page_data_7}}"
|
||||
fail="{{page_data_6}}"
|
||||
text="{{page_data_8}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_2"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="startLocationUpdateBackground演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_9}}"
|
||||
complete="{{page_data_11}}"
|
||||
fail="{{page_data_10}}"
|
||||
text="{{page_data_12}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_3"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="stopLocationUpdate演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_13}}"
|
||||
complete="{{page_data_15}}"
|
||||
fail="{{page_data_14}}"
|
||||
text="{{page_data_16}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_4"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="chooseLocation演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_19}}"
|
||||
complete="{{page_data_21}}"
|
||||
fail="{{page_data_20}}"
|
||||
text="{{page_data_22}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<view class="_ui-input">
|
||||
<input placeholder="latitude" type="text" bindinput="page_fun_6" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="longitude" type="text" bindinput="page_fun_7" />
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_5"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="openLocation演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_28}}"
|
||||
complete="{{page_data_30}}"
|
||||
fail="{{page_data_29}}"
|
||||
text="{{page_data_31}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<view class="_ui-input">
|
||||
<input placeholder="latitude" type="text" bindinput="page_fun_9" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="longitude" type="text" bindinput="page_fun_10" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="scale" type="text" bindinput="page_fun_11" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="name" type="text" bindinput="page_fun_12" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="address" type="text" bindinput="page_fun_13" />
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_8"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
</view>
|
||||
Reference in New Issue
Block a user