定位
1、清单文件中勾选高德定位,并填写对应的key
2、微信环境需要初始化高德定位插件
// #ifdef MP-WEIXIN
this.globalData.amapPlugin = new amap.AMapWX({
key: this.globalData.key
});
// #endif
3、获取定位
// #ifdef APP-PLUS
uni.getLocation({
type: 'gcj02',
geocode: true,
success: (res) => {
var address = res.address.city + res.address
.district + res
.address.street + res
.address
.streetNum + res.address.poiName
this.saveLocation({
latitude: res.latitude,
longitude: res.longitude,
speed: res.speed,
accuracy: res.accuracy,
altitude: res.altitude,
address: address
});
console.log('当前位置信息:' + JSON.stringify(res));
},
fail: (res) => {
console.log('获取位置失败:' + JSON.stringify(res));
}
});
// #endif
// #ifdef MP-WEIXIN
this.globalData.amapPlugin.getRegeo({
success: (data) => {
this.saveLocation({
latitude: data[0].latitude,
longitude: data[0].longitude,
speed: '',
accuracy: '',
altitude: '',
address: data[0].regeocodeData.formatted_address
});
/* console.log('当前位置信息:' + JSON.stringify(this.globalData
.location)); */
}
});
// #endif
Map组件
使用map组件进行地图标点时,IOS必须要id,width,height属性,否则标点无法正常显示
this.covers = [
{
id:0,
width:50,
height:50,
latitude: this.location.latitude,
longitude: this.location.longitude,
iconPath: '/static/images/Location.png'
}
];
导航
IOS上唤起百度高德APP导航页面时需要将url中的中文字符编码,否则调用不成功
this.urlAMap = 'iosamap://path?sourceApplication=applicationName&sid=&slat='+this.location.latitude+'&slon='+this.location.longitude+'&sname='+encodeURIComponent(this.location.address)+'&did=&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&t=0';
this.urlBaiduMap =
'baidumap://map/direction?origin=' +encodeURIComponent(this.location.address) +
'&destination=39.98871,116.43234'+'&coord_type=gcj02&mode=driving&src=ios.baidu.openAPIdemo';