定位

1、清单文件中勾选高德定位,并填写对应的key
2、微信环境需要初始化高德定位插件

  1. // #ifdef MP-WEIXIN
  2. this.globalData.amapPlugin = new amap.AMapWX({
  3. key: this.globalData.key
  4. });
  5. // #endif

3、获取定位

  1. // #ifdef APP-PLUS
  2. uni.getLocation({
  3. type: 'gcj02',
  4. geocode: true,
  5. success: (res) => {
  6. var address = res.address.city + res.address
  7. .district + res
  8. .address.street + res
  9. .address
  10. .streetNum + res.address.poiName
  11. this.saveLocation({
  12. latitude: res.latitude,
  13. longitude: res.longitude,
  14. speed: res.speed,
  15. accuracy: res.accuracy,
  16. altitude: res.altitude,
  17. address: address
  18. });
  19. console.log('当前位置信息:' + JSON.stringify(res));
  20. },
  21. fail: (res) => {
  22. console.log('获取位置失败:' + JSON.stringify(res));
  23. }
  24. });
  25. // #endif
  26. // #ifdef MP-WEIXIN
  27. this.globalData.amapPlugin.getRegeo({
  28. success: (data) => {
  29. this.saveLocation({
  30. latitude: data[0].latitude,
  31. longitude: data[0].longitude,
  32. speed: '',
  33. accuracy: '',
  34. altitude: '',
  35. address: data[0].regeocodeData.formatted_address
  36. });
  37. /* console.log('当前位置信息:' + JSON.stringify(this.globalData
  38. .location)); */
  39. }
  40. });
  41. // #endif

Map组件

使用map组件进行地图标点时,IOS必须要id,width,height属性,否则标点无法正常显示

  1. this.covers = [
  2. {
  3. id:0,
  4. width:50,
  5. height:50,
  6. latitude: this.location.latitude,
  7. longitude: this.location.longitude,
  8. iconPath: '/static/images/Location.png'
  9. }
  10. ];

导航

IOS上唤起百度高德APP导航页面时需要将url中的中文字符编码,否则调用不成功

  1. 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';
  2. this.urlBaiduMap =
  3. 'baidumap://map/direction?origin=' +encodeURIComponent(this.location.address) +
  4. '&destination=39.98871,116.43234'+'&coord_type=gcj02&mode=driving&src=ios.baidu.openAPIdemo';