本地安卓项目配置
官网教程
*如果配置好编译报错:weex_amap-release.aar 如没有请忽略参考解决网址
如果需本地离线打包项目教程=》离线打报教程
获取本地jks SHA1高德申请key会用到
如有请忽略 生成本地jks文件
**记得将证书信息截图后面生成会用到**
获取已有证书SHA1
在存放证书目录打开cmd

输入: keytool -v -list -storetype jks -keystore XXX.jks或keytool -v -list -keystore keystore XXX.jks 或 keytool -list -v -keystore keystore XXX.jks
调试SHA1
Win+R打开新的cmd输入:*默认密码为:android
cd .android keytool -list -v -keystore debug.keystore详细说明请参考高德教程
高德地图申请key
uniapp 配置高德key
申请高德或者百度的key,在manifest.json --> App SDK中勾选地图和定位服务,在App模块权限配置中勾选Maps,这样我们可以获取更多的位置服务权限。
参考来源
uniapp编码部分
//定位权限
export const openPosition = ()=>{
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:'请打开定位服务功能',
showCancel:false,
success() {
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);//打开系统设置GPS服务页面
}else{
uni.showToast({
title:'定位功能已启动',
duration:2000
})
}
}
})
}
}
}
//获取当前的地理位置坐标
getCurLocation(){
uni.getLocation({
geocode:true,
type: 'gcj02',
success:async (res)=>{
let { pois } = await posToCity(
{
latitude: res.latitude,
longitude: res.longitude,
},
1
);
this.address = pois[0].title
this.latitude = res.latitude
this.longitude = res.longitude
uni.setStorageSync('latitude',res.latitude)
uni.setStorageSync('longitude',res.longitude)
this.curAddress = store.state.address.curPickAddress.title
}
})
}
// 高德坐标解析
export const posToCity = async (location, extensions = 0) => new Promise((resolve, reject) => {
uni.request({
url: `https://restapi.amap.com/v3/geocode/regeo`,
method: 'GET',
data: {
key: gdMapKey,
location: `${location.longitude},${location.latitude}`,
extensions: extensions ? 'all' : 'base'
},
success: ({data}) => {
const {status, info, regeocode} = data
if (status === '1') {
// console.log(regeocode)
if ('pois' in regeocode) {
regeocode.pois = regeocode.pois.filter(item => typeof item.address === 'string' && typeof item.location === 'string').map(item => ({
id: item.id,
title: item.name,
address: item.address,
location: {
lat: item.location.split(',')[1],
lng: item.location.split(',')[0]
}
}))
}
resolve(regeocode)
} else {
reject(info)
}
},
fail: err => {
reject(err)
}
})
})
来源