uniapp使用uni.chooseLocation()打開(kāi)地圖選擇位置詳解
使用uni.chooseLocation()打開(kāi)地址選擇位置
1、打開(kāi)微信開(kāi)發(fā)平臺(tái)申請(qǐng)權(quán)限
【開(kāi)發(fā)】–【開(kāi)發(fā)管理】–【接口設(shè)置】–點(diǎn)擊去開(kāi)通,開(kāi)通之后才可以使用。
2、對(duì)小程序進(jìn)行設(shè)置
“requiredPrivateInfos”:[“chooseLocation”]
1.第一種在 uniapp進(jìn)行設(shè)置
2.第二種在原生微信小程序上設(shè)置
3、在app.vue里添加微信用戶授權(quán)
onLaunch: function() { uni.authorize({ scope: 'scope.userLocation', success: function () { console.log('用戶同意了授權(quán)') } }) },
4、在頁(yè)面調(diào)起地圖選擇
<template> <view class="content"> <button @tap="authVerification">請(qǐng)選擇位置</button> <template v-if="currentLocation.address"> <div>name:{{currentLocation.name}}</div> <div>address:{{currentLocation.address}}</div> <div>latitude:{{currentLocation.latitude}}</div> <div>longitude:{{currentLocation.longitude}}</div> </template> </view> </template> <script> export default { data() { return { currentLocation:{}, } }, onShow () { uni.getStorage({ key: 'currentLocation', success: (res) => { this.currentLocation = res.data } }) }, methods: { authVerification () { uni.getSetting({ success: (res) => { if (res.authSetting['scope.userLocation']) { /* 用戶授權(quán)成功時(shí)走這里 */ this.handerChooseLocation() } else if (res.authSetting['scope.userLocation'] === undefined) { /* 用戶未授權(quán)時(shí)走這里 */ console.log('沒(méi)有授權(quán)') this.handleOpenSetting() } else { /* 用戶拒絕了授權(quán)后走這里 */ console.log('拒絕了授權(quán) false') this.handleOpenSetting() } }, }) }, handerChooseLocation (latitude, longitude) { uni.chooseLocation({ latitude: latitude || '', longitude: longitude || '', success: (res) => { console.log('wx.chooseLocation res=', res) uni.setStorageSync('currentLocation', res) }, fail: function (err) { console.log('取消按鈕', err) } }) }, handleOpenSetting () { wx.openSetting({ success: (res) => { console.log('定位 openSetting', res) if (res.authSetting["scope.userLocation"]) { this.handerChooseLocation() } } }) } } } </script>
總結(jié)
到此這篇關(guān)于uniapp使用uni.chooseLocation()打開(kāi)地圖選擇位置的文章就介紹到這了,更多相關(guān)uniapp打開(kāi)地圖選擇位置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
函數(shù)式 JavaScript(一)簡(jiǎn)介
JavaScript 是一種強(qiáng)大但被誤解的語(yǔ)言。關(guān)于它到底是一種面向?qū)ο蟮恼Z(yǔ)言還是函數(shù)式語(yǔ)言,人們眾說(shuō)紛紜——但是現(xiàn)在讓我們把這些爭(zhēng)辯都拋到腦后。2014-07-07JavaScript 類型轉(zhuǎn)換的詳細(xì)實(shí)現(xiàn)
本文主要介紹了JavaScript 類型轉(zhuǎn)換的詳細(xì)實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02微信小程序?qū)崿F(xiàn)比較功能的方法匯總(五種方法)
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)比較功能的方法,本文給大家列舉出五種方式,每種方法通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03關(guān)于base64編碼和解碼的js工具函數(shù)
這篇文章主要介紹了關(guān)于base64編碼和解碼的js工具函數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02js實(shí)現(xiàn)當(dāng)復(fù)選框選擇匿名登錄時(shí)隱藏登錄框效果
這篇文章主要介紹了js實(shí)現(xiàn)當(dāng)復(fù)選框選擇匿名登錄時(shí)隱藏登錄框效果,實(shí)例分析了javascript動(dòng)態(tài)操作頁(yè)面元素樣式的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-08-08JavaScript實(shí)現(xiàn)秒殺時(shí)鐘倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)秒殺時(shí)鐘倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-09-09