提交 71d8c013 编写于 作者: Anne_LXM's avatar Anne_LXM

同步uni1 web端api示例(地图选择/查看位置)

上级 de036deb
...@@ -400,6 +400,20 @@ ...@@ -400,6 +400,20 @@
"navigationBarTitleText" : "editor" "navigationBarTitleText" : "editor"
} }
}, },
{
"path" : "pages/API/open-location/open-location",
"style" :
{
"navigationBarTitleText" : "open-location"
}
},
{
"path" : "pages/API/choose-location/choose-location",
"style" :
{
"navigationBarTitleText" : "choose-location"
}
},
// #endif // #endif
{ {
"path": "pages/component/list-view/issue-2199", "path": "pages/component/list-view/issue-2199",
......
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap">
<view style="background:#FFFFFF; padding:40rpx;">
<view class="uni-hello-text uni-center">当前位置信息</view>
<block v-if="hasLocation === false">
<view class="uni-h2 uni-center uni-common-mt">未选择位置</view>
</block>
<block v-if="hasLocation === true">
<view class="uni-hello-text uni-center" style="margin-top:10px;">
{{locationAddress}}
</view>
<view class="uni-h2 uni-center uni-common-mt">
<text>E: {{location.longitude[0]}}°{{location.longitude[1]}}′</text>
<text>\nN: {{location.latitude[0]}}°{{location.latitude[1]}}′</text>
</view>
</block>
</view>
<view class="uni-btn-v">
<button type="primary" @tap="chooseLocation">选择位置</button>
<button @tap="clear">清空</button>
</view>
</view>
</view>
</template>
<script lang="uts">
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('.')
}
}
export default {
data() {
return {
title: 'chooseLocation',
hasLocation: false,
location: {},
locationAddress: ''
}
},
methods: {
chooseLocation: function () {
uni.chooseLocation({
success: (res) => {
console.log(res,123)
this.hasLocation = true,
this.location = formatLocation(res.longitude, res.latitude),
this.locationAddress = res.address
}
})
},
clear: function () {
this.hasLocation = false
}
}
}
</script>
<style>
.page-body-info {
padding-bottom: 0;
height: 440rpx;
}
</style>
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-common-mt">
<form @submit="openLocation">
<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-left">
<view class="uni-label">经度</view>
</view>
<view class="uni-list-cell-db">
<input class="uni-input" type="text" :disabled="true" value="116.39747" name="longitude"/>
</view>
</view>
<view class="uni-list-cell">
<view class="uni-list-cell-left">
<view class="uni-label">纬度</view>
</view>
<view class="uni-list-cell-db">
<input class="uni-input" type="text" :disabled="true" value="39.9085" name="latitude"/>
</view>
</view>
<view class="uni-list-cell">
<view class="uni-list-cell-left">
<view class="uni-label">位置名称</view>
</view>
<view class="uni-list-cell-db">
<input class="uni-input" type="text" :disabled="true" value="天安门" name="name"/>
</view>
</view>
<view class="uni-list-cell">
<view class="uni-list-cell-left">
<view class="uni-label">详细位置</view>
</view>
<view class="uni-list-cell-db">
<input class="uni-input" type="text" :disabled="true" value="北京市东城区东长安街" name="address"/>
</view>
</view>
</view>
<view class="uni-padding-wrap">
<view class="uni-btn-v uni-common-mt">
<button type="primary" formType="submit">查看位置</button>
</view>
</view>
</form>
</view>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
title: 'openLocation'
}
},
methods: {
openLocation: function (e) {
console.log(e)
var value = e.detail.value
uni.openLocation({
longitude: Number(value.longitude),
latitude: Number(value.latitude),
name: value.name,
address: value.address
})
}
}
}
</script>
<style>
.uni-list-cell-left {
padding: 0 30rpx;
}
</style>
...@@ -206,13 +206,13 @@ ...@@ -206,13 +206,13 @@
name: 'showToast轻提示框', name: 'showToast轻提示框',
url: 'toast', url: 'toast',
api: ["showToast"] api: ["showToast"]
} }
// #ifdef APP // #ifdef APP
,{ ,{
name: '主题切换', name: '主题切换',
url: 'theme-change', url: 'theme-change',
api: ["setAppTheme","onOsThemeChange","offOsThemeChange","onAppThemeChange","offAppThemeChange"] api: ["setAppTheme","onOsThemeChange","offOsThemeChange","onAppThemeChange","offAppThemeChange"]
} }
// #endif // #endif
] as Page[], ] as Page[],
}, },
...@@ -292,14 +292,14 @@ ...@@ -292,14 +292,14 @@
{ {
name: "打电话", name: "打电话",
url: "make-phone-call", url: "make-phone-call",
}, },
{ {
name: "剪贴板", name: "剪贴板",
url: "clipboard", url: "clipboard",
}, },
{ {
name: "监听罗盘数据", name: "监听罗盘数据",
url: "on-compass-change", url: "on-compass-change",
}, },
// #endif // #endif
/* /*
...@@ -426,11 +426,6 @@ ...@@ -426,11 +426,6 @@
}, },
// #ifdef WEB // #ifdef WEB
{ {
name: "地图控制",
url: "map",
},
// #endif
/* {
name: "使用地图查看位置", name: "使用地图查看位置",
url: "open-location", url: "open-location",
}, },
...@@ -438,6 +433,8 @@ ...@@ -438,6 +433,8 @@
name: "使用地图选择位置", name: "使用地图选择位置",
url: "choose-location", url: "choose-location",
}, },
// #endif
/*
{ {
name: "地图搜索", name: "地图搜索",
url: "map-search", url: "map-search",
...@@ -503,24 +500,24 @@ ...@@ -503,24 +500,24 @@
url: 'facial-recognition-verify', url: 'facial-recognition-verify',
} }
] as Page[], ] as Page[],
}, },
{ {
id: 'ad', id: 'ad',
name: '广告', name: '广告',
pages: [ pages: [
{ {
name: '激励视频广告', name: '激励视频广告',
url: 'rewarded-video-ad', url: 'rewarded-video-ad',
} }
/* { /* {
id: "full-screen-video-ad", id: "full-screen-video-ad",
url: "full-screen-video-ad", url: "full-screen-video-ad",
name: "全屏视频广告", name: "全屏视频广告",
enable: false, enable: false,
pages: [] as Page[] pages: [] as Page[]
}, */ }, */
] as Page[], ] as Page[],
}, },
// #endif // #endif
{ {
id: "payment", id: "payment",
...@@ -630,4 +627,4 @@ ...@@ -630,4 +627,4 @@
display: none; display: none;
background-color: rgba(16, 16, 16, 0.5); background-color: rgba(16, 16, 16, 0.5);
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册