uniapp?App端使用高德地圖超詳細(xì)步驟
uniapp App端使用高德地圖
第一步:
先去高德官網(wǎ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包名和你需要云打包的項目Android包名一樣

第二步:
打開項目manifest.json文件,將所需的權(quán)限配置好


第三步:
下載微信小程序SDK:https://lbs.amap.com/api/wx/download
然后放進uni項目,在需要用的到頁面引入
import amap from "../../../common/amap-wx.130.js";//微信小程序SDK
export default {
data() {
return {
key: "高德申請的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 是在高德中申請的微信小程序key
});
this.amapPlugin.getRegeo({
// type: 'gcj02', //map 組件使用的經(jīng)緯度是國測局坐標(biāo), type 為 gcj02
success: function(res) {
console.log('app端地圖')
console.log(res);
_this.getCurLocation();
},
fail: (res) => {
console.log(res);
//檢測app端是否開啟權(quán)限
_this.openPosition();
}
});
},
openPosition() {
const _this = this;
let system = uni.getSystemInfoSync()
if (system.platform === 'android') { //判斷平臺
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: '請在設(shè)置中打開定位服務(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); //打開系統(tǒng)設(shè)置GPS服務(wù)頁面
} else {
uni.showToast({
title: '定位功能已啟動',
duration: 2000
})
}
} else if (res.cancel) {
// 拒絕授權(quán)返回上一頁
_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包名和申請高德key填寫的PackageName一致
選擇自有證書,如果使用公共測試證書的話,uni.chooseLocation這個方法會搜索不到位置
別名、證書私鑰密碼、證書文件請查看圖二生成的秘鑰



總結(jié)
到此這篇關(guān)于uniapp App端使用高德地圖的文章就介紹到這了,更多相關(guān)uniapp App端用高德地圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
javascript獲取鼠標(biāo)位置部分的實例代碼(兼容IE,FF)
這篇文章介紹了javascript獲取鼠標(biāo)位置部分的實例代碼,有需要的朋友可以參考一下2013-08-08
三種動態(tài)加載js的jquery實例代碼另附去除js方法
這篇文章主要介紹了三種動態(tài)加載js的jquery實例代碼另附去除js方法,需要的朋友可以參考下2014-04-04
JavaScript中獲取鼠標(biāo)位置相關(guān)屬性總結(jié)
這篇文章主要介紹了JavaScript中獲取鼠標(biāo)位置相關(guān)屬性總結(jié),本文重點在搞清楚這些屬性的區(qū)別,需要的朋友可以參考下2014-10-10
超全面的JavaScript開發(fā)規(guī)范(推薦)
作為一名開發(fā)人員(WEB前端JavaScript開發(fā)),不規(guī)范的開發(fā)不僅使日后代碼維護變的困難,同時也不利于團隊的合作,通常還會帶來代碼安全以及執(zhí)行效率上的問題。本文就主要介紹了關(guān)于Javascript的命名規(guī)范、注釋規(guī)范以及框架開發(fā)的一些問題,需要的朋友可以參考學(xué)習(xí)。2017-01-01

