2025-06-06 03:08:19 +08:00

61 lines
1.6 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<nav-bar title="获取当前经纬度"></nav-bar>
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<view class="table_box">
<view class="table_title">使用文档</view>
<view class="table_content">
<text>兼容公众号APP微信小程序</text>
</view>
<view class="table_content">
<text>公众号环境需要获取公众号SDK权限</text>
</view>
<view class="table_content">
<text>获取成功后经纬度会自动储存到vuex的config/store.js => currentAddress参数里面</text>
</view>
</view>
<view class="input_form_box">
<view class="input_box btm_line">
<view class="name">获取经纬度</view>
<view class="select_info" @click="onGetLatLon">
<view class="value" v-if="currentAddress.latitude">{{currentAddress.latitude}},{{currentAddress.longitude}}</view>
<view class="select" v-else>请选择</view>
</view>
</view>
</view>
</view>
</template>
<script>
import { getLatLon } from '@/config/utils';
import { mapState, mapMutations } from 'vuex';
export default {
data() {
return {
};
},
computed: {
...mapState(['currentAddress'])
},
//方法
methods: {
async onGetLatLon() {
// true 有错误提示
// false 没错误提示
// 成功后经纬度会自动储存到vuex的config/store.js => currentAddress参数里面
const data = await getLatLon(true);
console.log("经纬度数据",data);
uni.showModal({
title:"经纬度",
content: "latitude="+ data.latitude + ", longitude=" + data.longitude
});
}
}
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';
</style>