前端Vue基于騰訊地圖Api實作的選擇位置組件 回傳地址名稱詳細地址經緯度資訊, 下載完整代碼請訪問uni-app插件市場地址:https://ext.dcloud.net.cn/plugin?id=13310
效果圖如下:
使用方法
<!-- leftTitle:左邊標題 name:輸入框名字 value:輸入框選擇值 placeholder:占位符 @click:點擊事件-->
<cc-locPicker leftTitle="識訓地點" name="location" :value="https://www.cnblogs.com/ccVue/archive/2023/07/02/mapSelData.poiname" placeholder="請選擇位置"
@click="chooseAddress"></cc-locPicker>
<!-- 跳轉騰訊云地圖Api 頁面實作 -->
<template>
<view >
<!-- 騰訊地圖Api key:騰訊地圖key -->
<web-view
src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI&referer=myapp"></web-view>
</view>
</template>
<script>
// 引入設定地址存盤工具
import {
setlocation
} from './utils.js'
// #ifdef H5
window.addEventListener('message', event => {
// 接收位置資訊,用戶選擇確認位置點后選點組件會觸發該事件,回傳用戶的位置資訊
var loc = event.data;
if (loc && loc.module == 'locationPicker') {
//防止其他應用也會向該頁面post資訊,需判斷module是否為'locationPicker'
let location = {
poiaddress: loc.poiaddress,
poiname: loc.poiname,
latlng: loc.latlng
}
// 設定存盤地址資訊
setlocation(location)
uni.navigateBack();
}
}, false);
// #endif
</script>
<style></style>
HTML代碼實作部分
<template>
<view >
<form @submit="formSubmit" @reset="formReset">
<!-- leftTitle:左邊標題 name:輸入框名字 value:輸入框選擇值 placeholder:占位符 @click:點擊事件-->
<cc-locPicker leftTitle="識訓地點" name="location" :value="https://www.cnblogs.com/ccVue/archive/2023/07/02/mapSelData.poiname" placeholder="請選擇位置"
@click="chooseAddress"></cc-locPicker>
<ccInputView leftTitle="詳細地址" name="address" :value="https://www.cnblogs.com/ccVue/archive/2023/07/02/mapSelData.poiaddress" placeholder="請輸入詳細地址">
</ccInputView>
<ccInputView leftTitle="經度資訊" name="lng" :value="https://www.cnblogs.com/ccVue/archive/2023/07/02/mapSelData.latlng.lng" placeholder="請輸入精度資訊">
</ccInputView>
<ccInputView leftTitle="緯度資訊" name="lat" :value="https://www.cnblogs.com/ccVue/archive/2023/07/02/mapSelData.latlng.lat" placeholder="請輸入緯度資訊">
</ccInputView>
<view >
<button type="primary" form-type="submit">下一步</button>
<view > 注意事項: 請確保您填寫的識訓位置準確 </view>
</view>
</form>
</view>
</template>
<script>
import ccInputView from '../../components/ccInputView.vue'
// 獲取地址工具
import {
getlocation
} from './utils.js'
export default {
components: {
ccInputView
},
data() {
return {
mapSelData: {
"latlng": {}
},
}
},
/**
* 生命周期函式--監聽頁面顯示
*/
onShow: function() {
// #ifdef H5
let locations = getlocation() //獲取位置資訊
if (locations) {
this.mapSelData = https://www.cnblogs.com/ccVue/archive/2023/07/02/locations
uni.clearStorageSync();
}
// #endif
},
methods: {
formSubmit: function(e) {
console.log('form發生了submit事件,攜帶資料為:' + JSON.stringify(e));
var formdata = https://www.cnblogs.com/ccVue/archive/2023/07/02/e.detail.value;
uni.showModal({
title:'溫馨提示',
content: 'formsubmit事件攜帶資料為:' + JSON.stringify(e.detail.value)
})
},
// 選擇地址
chooseAddress(e) {
let myThis = this;
uni.navigateTo({
url: './h5map'
})
},
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
}
.uni-btn-v {
width: 100%;
height: auto;
}
.botBtn {
width: 90%;
margin-top: 36px;
}
.tipText {
width: 100%;
margin-left: 0px;
text-align: center;
color: #666666;
margin-top: 36px;
margin-bottom: 36px;
font-size: 28rpx;
}
</style>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/556509.html
標籤:其他
下一篇:返回列表