uniapp?App端使用高德地圖超詳細(xì)步驟
uniapp App端使用高德地圖
第一步:
先去高德官網(wǎng)申請(qǐng)keyhttps://console.amap.com/dev/key/app
關(guān)于SHA1生成方法如下:https://lbs.amap.com/faq/android/map-sdk/create-project/43112
我使用的是使用 keytool(jdk自帶工具)獲取SHA1
PackageName包名和你需要云打包的項(xiàng)目Android包名一樣
第二步:
打開(kāi)項(xiàng)目manifest.json文件,將所需的權(quán)限配置好
第三步:
下載微信小程序SDK:https://lbs.amap.com/api/wx/download
然后放進(jìn)uni項(xiàng)目,在需要用的到頁(yè)面引入
import amap from "../../../common/amap-wx.130.js";//微信小程序SDK export default { data() { return { key: "高德申請(qǐng)的key", amapPlugin: null, } }, onLoad(options) { // #ifdef APP-PLUS this.getAppLocation(); // #endif }, }
methods: { //高德地圖 getAppLocation() { const _this = this; this.amapPlugin = new amap.AMapWX({ key: this.key //該key 是在高德中申請(qǐng)的微信小程序key }); this.amapPlugin.getRegeo({ // type: 'gcj02', //map 組件使用的經(jīng)緯度是國(guó)測(cè)局坐標(biāo), type 為 gcj02 success: function(res) { console.log('app端地圖') console.log(res); _this.getCurLocation(); }, fail: (res) => { console.log(res); //檢測(cè)app端是否開(kāi)啟權(quán)限 _this.openPosition(); } }); }, openPosition() { const _this = this; let system = uni.getSystemInfoSync() if (system.platform === 'android') { //判斷平臺(tái) var context = plus.android.importClass("android.content.Context") var locationManager = plus.android.importClass("android.location.LocationManager") var main = plus.android.runtimeMainActivity() var mainSvr = main.getSystemService(context.LOCATION_SERVICE) console.log('GPS', mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { uni.showModal({ title: '提示', content: '請(qǐng)?jiān)谠O(shè)置中打開(kāi)定位服務(wù)功能', success(res) { if (res.confirm) { if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { let main = plus.android.runtimeMainActivity(); let Intent = plus.android.importClass("android.content.Intent"); let mIntent = new Intent('android.settings.ACTION_SETTINGS'); main.startActivity(mIntent); //打開(kāi)系統(tǒng)設(shè)置GPS服務(wù)頁(yè)面 } else { uni.showToast({ title: '定位功能已啟動(dòng)', duration: 2000 }) } } else if (res.cancel) { // 拒絕授權(quán)返回上一頁(yè) _this.goBack(); } } }) } else { //獲取當(dāng)前用戶所在位置 _this.getCurLocation(); } } }, getCurLocation() { const _this = this; uni.getLocation({ geocode: true, type: 'gcj02', success: async (res) => { console.log(res); } }) }, //搜索地圖 getLcotion() { const _this = this; uni.chooseLocation({ success(list) { console.log(list); } }) }, }
最后云打包:
Android包名和申請(qǐng)高德key填寫的PackageName一致
選擇自有證書,如果使用公共測(cè)試證書的話,uni.chooseLocation這個(gè)方法會(huì)搜索不到位置
別名、證書私鑰密碼、證書文件請(qǐng)查看圖二生成的秘鑰
總結(jié)
到此這篇關(guān)于uniapp App端使用高德地圖的文章就介紹到這了,更多相關(guān)uniapp App端用高德地圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
奉獻(xiàn)給JavaScript初學(xué)者的編寫開(kāi)發(fā)的七個(gè)細(xì)節(jié)
每種語(yǔ)言都有它特別的地方,對(duì)于JavaScript來(lái)說(shuō),使用var就可以聲明任意類型的變量,這門腳本語(yǔ)言看起來(lái)很簡(jiǎn)單,然而想要寫出優(yōu)雅的代碼卻是需要不斷積累經(jīng)驗(yàn)的。本文利列舉了JavaScript初學(xué)者應(yīng)該注意的七個(gè)細(xì)節(jié),與大家分享。2011-01-01快速解決layui彈窗按enter鍵不停彈窗的問(wèn)題
今天小編就為大家分享一篇快速解決layui彈窗按enter鍵不停彈窗的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09