更新记录

1.0.3(2025-11-14)

  1. 更新资源文件

1.0.2(2025-11-14)

  1. 增加harmony支持

1.0.1(2025-11-10)

  1. 增加地图样式、定位样式、交通图、室内图
  2. 支持地图上绘制点标记、地图选点
  3. 支持地理位置、正反地理位置编码
  4. 起始点导航、途径点导航
  5. 离线地图
查看更多

平台兼容性

uni-app(3.6.14)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
- - 5.0
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - -

uni-app x(3.6.14)

Chrome Safari Android iOS 鸿蒙 微信小程序
- - 5.0 -

其他

多语言 暗黑模式 宽屏模式

前言

高德官方demo功能实现,支持地图样式、定位样式、交通图、室内图等等,支持地图上绘制点标记、地图选点等等,支持地理位置、反地理位置编码,周边美食、景点等搜索,实时导航

快速接入

  1. 在高德地图开放平台(https://console.amap.com/dev/key/app)[https://console.amap.com/dev/key/app]创建Android、iOS、harmony应用的key,harmony需要先给项目签名,然后调用getAppId()获取appID绑定到高德平台上
  2. 记录下开放平台上各个的appkey
  3. 将demo里的AndroidManifest.xml、Info.plist、harmony-configs拷贝到项目到根目录,并替换AndroidManifest.xml里application节点下meta-data节点的appkey值,iOS和harmony通过app启动的时候代码设置 setAMapAPIKey("xxxx")
  4. ios需要在后台运行能力里增加location,manifest.json->App常用其他配置-> 后台运行能力添加location
  5. 集成插件步骤请参考https://www.cnblogs.com/wenrisheng/p/18323027
定制请点击上面"进入交流群"按钮私聊作者

高德地图版本: Android:V10.1.600 ios:V10.1.600 harmony:V2.2.4

接口


    import {
    updatePrivacyShow,
    updatePrivacyAgree,
    setAMapAPIKey,
    setTerrainEnabled,
    toOffineMapPage,
    getScreenInfo,
    coordinateConvert,
    metersBetweenMapPoints,
    circleContainsCoordinate,
    calculateArea,
    UTSAMapNaviCompositeManager
} from "@/uni_modules/wrs-uts-amapview"

在使用地图接口或控件弹框提示用户地图的合规接口,具体可参考示例demo

  1. 更新App是否显示隐私弹窗的状态

更新App是否显示隐私弹窗的状态,隐私弹窗是否包含高德SDK隐私协议内容的状态. 注意:必须在MAMapView实例化之前调用


let isContains = true
let isShow = true
updatePrivacyShow(isContains, isShow)
  1. 更新用户授权高德SDK隐私协议状态

let isAgree = true
updatePrivacyAgree(isAgree)

创建地图&与地图交互&在地图上绘制


<!--  #ifdef  APP-HARMONY -->
<embed :style="'width:'+width+'px;height:'+height+'px;'" tag="amapview" :options="options"
    @onevent="onEvent"></embed>
<!--  #endif -->
<!--  #ifndef  APP-HARMONY -->
<wrs-uts-amapview ref='mapview' :params="params" :style="'width:'+width+'px;height:'+height+'px;'"
    @onEvent="onEvent"></wrs-uts-amapview>
<!--  #endif -->

回调接口

  1. onEvent
onEvent(event) {
    console.log("onEvent:" + JSON.stringify(event))
    let detail = event.detail
    let opt = detail.opt
    switch (opt) {
        case "onLoadView":

            break;
        case "onSucLoadMap": {

        }
        break;
        case "onFailLoadMap": {

        }
        break;
        case "onRegionDidChange": {

        }
        break;
        case "onDidMove": {

        }
        break;
        case "onUpdateLocation": {

        }
        break;
        case "onClickAnnotationMarker": {
            this.showToast("点击了图标")
            let annotation = detail.annotation
            console.log(JSON.stringify(annotation))
        }
        break;
        case "onClickCallout": {
            this.showToast("点击了气泡")
            let annotation = detail.annotation
            console.log(JSON.stringify(annotation))
        }
        break;
        default:
            break;
    }
}

地图接口,地图业务接口都是通过params属性来控制

如:


let params = {}
params.businessArray = [{
    business: "showTraffic", // 业务:是否显示交通图
    params: { // 业务参数
        show: true
    }
}]

let paramsStr = this.formatNewParams(params)
// android、ios
this.params = paramsStr
// 鸿蒙
this.options = {
    params: paramsStr
}
  1. 设置地图图层类型

let titles = ["普通模式", "卫星模式", "夜景模式", "导航模式", "公交模式", "导航夜间模式"]
let values = ["normal", "satellite", "night", "navi", "bus", "navi_night"]

this.showActionSheet(titles, (index) => {
    let newParams = {}
    newParams.businessArray = [{
        business: "setMapType", // 业务
        params: {
            type: values[index]
        }
    }]

    let newParamsStr = this.formatNewParams(newParams)
    // android、ios
    this.params = newParamsStr
    // 鸿蒙
    this.options = {
        params: newParamsStr
    }
})
  1. 用户跟踪模式

let titles = []
let values = []
switch (uni.getSystemInfoSync().platform) {
    // android
    case 'android': {
        titles = ["显示", "定位", "跟随", "旋转", "定位旋转", "定位旋转中心不动", "跟随中心不动", "旋转中心不动"];
        values = ["show", "locate", "follow", "map_rotate", "location_rotate", "location_rotate_no_center", "follow_no_center", "map_rotate_no_center"]
    }
    break;
    case 'ios': {
        titles = ["普通模式", "追踪", "方向追踪"]
        values = ["none", "follow", "followWithHeading"]
    }
    break;
    case 'harmonyos': {
        titles = ["显示", "定位", "跟随", "旋转", "定位旋转", "定位旋转中心不动", "跟随中心不动", "旋转中心不动"];
        values = ["show", "locate", "follow", "map_rotate", "location_rotate", "location_rotate_no_center", "follow_no_center", "map_rotate_no_center"]
    }
    break;
    default:
        break;
}
this.showActionSheet(titles, (index) => {
    let newParams = {}
    newParams.businessArray = [{
        business: "setUserTrackingMode", // 业务
        params: {
            type: values[index],
            animated: true // 仅支持iOS
        }
    }]

    let newParamsStr = this.formatNewParams(newParams)
    // android、ios
    this.params = newParamsStr
    // 鸿蒙
    this.options = {
        params: newParamsStr
    }
})

ios:

  • none: 不追踪用户的location更新
  • follow: 追踪用户的location更新
  • followWithHeading: 追踪用户的location与heading更新

android:

  • show: 只定位,不进行其他操作
  • locate: 追踪用户的location更新
  • follow: 设置定位的类型为 跟随模式
  • map_rotate: 设置定位的类型为根据地图面向方向旋转
  • location_rotate: 定位、且将视角移动到地图中心点,定位点依照设备方向旋转,  并且会跟随设备移动。
  • location_rotate_no_center: 定位、但不会移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。
  • follow_no_center: 定位、但不会移动到地图中心点,并且会跟随设备移动。
  • map_rotate_no_center: 定位、但不会移动到地图中心点,地图依照设备方向旋转,并且会跟随设备移动。

harmony:

  • show:只定位
  • locate:定位、且将视角移动到地图中心点
  • follow:定位、且将视角移动到地图中心点,定位点跟随设备移动。
  • map_rotate:定位、且将视角移动到地图中心点,地图依照设备方向旋转,定位点会跟随设备移动。
  • location_rotate:定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。
  • location_rotate_no_center:定位、但不会移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。
  • follow_no_center:定位、但不会移动到地图中心点,并且会跟随设备移动
  • map_rotate_no_center:定位、但不会移动到地图中心点,地图依照设备方向旋转,并且会跟随设备移动。
  1. 是否显示用户位置

let newParams = {}
newParams.businessArray = [{
    business: "showsUserLocation", // 业务
    params: {
        show: true
    }
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 是否显示交通路况图层

let newParams = {}
newParams.businessArray = [{
    business: "showTraffic", // 业务
    params: {
        show: true
    }
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 是否室内地图,暂不支持harmony

let newParams = {}
newParams.businessArray = [{
    business: "showIndoorMap", // 业务
    params: {
        show: true
    }
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 自定义地图样式

let newParams = {}
newParams.businessArray = [{
    business: "customMapStyle", // 业务
    params: {
        enable: true, // 是否启动
        path: "/xxxx/xxxxx/my_style_new.data" // 本地样式文件绝对路径
    }
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 自定义系统定位蓝点

var params = {}
params.image = "/xx/xx/aa.png" // 定位图标, 与蓝色原点互斥,本地图片绝对路径
params.strokeColor = "#00FF00" // 精度圈 边线颜色
params.fillColor = "#00FF00" // 精度圈 填充颜色
params.lineWidth = 2 // 精度圈 边线宽度

params.locationDotBgColor = "#00FF00" // 定位点背景色,不设置默认白色,仅支持iOS
params.locationDotFillColor = "#00FF00" // 定位点蓝色圆点颜色,不设置默认蓝色,仅支持iOS
params.showsAccuracyRing = true // 精度圈是否显示,默认YES,仅支持iOS
params.showsHeadingIndicator = true // 是否显示方向指示(MAUserTrackingModeFollowWithHeading模式开启)。默认为YES,仅支持iOS
params.enablePulseAnnimation = true // 内部蓝色圆点是否使用律动效果, 默认YES,仅支持iOS

let newParams = {}
newParams.businessArray = [{
    business: "customMyLocationStyle", // 业务
    params: params
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 设置地图中心点

let newParams = {}
newParams.businessArray = [{
    business: "setCenterCoordinate", // 业务
    params: {
         latitude: 12.2
         longitude: 15.0,
         animated: true // 仅支持Android
    }
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 设置缩放级别

let newParams = {}
newParams.businessArray = [{
    business: "setZoomLevel", // 业务
    params: {
        zoomLevel: 5 // 3-19,有室内地图时为3-20
         animated: true 
    }
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 地图放大一级

let newParams = {}
newParams.businessArray = [{
    business: "zoomIn", // 业务
    params: {
         animated: true 
    }
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 地图缩小一级

let newParams = {}
newParams.businessArray = [{
    business: "zoomOut", // 业务
    params: {
         animated: true 
    }
}]

let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 设置最小缩放级别

let newParams = {}
newParams.businessArray = [{
    business: "setMinZoomLevel", // 业务
    params: {
         zoomLevel: 3 
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 设置最大缩放级别

let newParams = {}
newParams.businessArray = [{
    business: "setMaxZoomLevel", // 业务
    params: {
         zoomLevel: 20
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 是否显示比例尺

let newParams = {}
newParams.businessArray = [{
    business: "showsScale", // 业务
    params: {
         show: true
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 是否显示指南针

let newParams = {}
newParams.businessArray = [{
    business: "showsCompass", // 业务
    params: {
         show: true
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 是否支持缩放

let newParams = {}
newParams.businessArray = [{
    business: "zoomEnabled", // 业务
    params: {
         show: true
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 是否支持滚动

let newParams = {}
newParams.businessArray = [{
    business: "scrollEnabled", // 业务
    params: {
         show: true
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 是否支持旋转

let newParams = {}
newParams.businessArray = [{
    business: "rotateEnabled", // 业务
    params: {
         show: true
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 设置logo中心点,暂不支持鸿蒙

let newParams = {}
newParams.businessArray = [{
    business: "setLogoCenter", // 业务
    params: {
         x: 20.1,
         y: 30.5
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 设置logo底部边距

let newParams = {}
newParams.businessArray = [{
    business: "setLogoBottomMargin", // 业务
    params: {
         margin: 12
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 绘制点标记

var image1 = "";
var image2 = "";

// ios会自动加载.png的1/2/3倍图
switch (uni.getSystemInfoSync().platform) {
    case 'android': {
        image1 = getResourcePath("/static/greenPin_lift.png");
        image2 = getResourcePath("/static/amap_through.png");
    }
    break;
    case 'harmonyos': {
        // 图片放到harmony-configs/entry/src/main/resources/rawfile文件夹下
        image1 =  "amap_end.png"
        image2 = "amap_start.png"
    }
    break;
    case 'ios': {
        image1 = getResourcePath("/static/greenPin_lift");
        image2 = getResourcePath("/static/amap_through");
    }
    break;
    default:
        break;
}
var latitudes = [39.992520, 39.992520, 39.998293, 40.004087, 40.001442, 39.989105, 39.989098,
    39.998439, 39.979590, 39.978234
];
var longitudes = [116.336170, 116.336170, 116.352343, 116.348904, 116.353915, 116.353915, 116.360200,
    116.360201, 116.324219, 116.352792
];
var annotationMarkers = [];
for (var i = 0; i < 1; i++) {
    var latitude = latitudes[i];
    var longitude = longitudes[i];
    var image = null;
    if (i % 2 == 0) {
        image = image1;
    } else {
        image = image2;
    }
    var selected = false;
    if (i == 0) {
        selected = true;
    }
    var lockedToScreen = false;
    // if (i == 0) {
    //  lockedToScreen = true;
    // }
    annotationMarkers.push({
        title: "北京" + i,
        subtitle: "北京是中国的首都" + i,
        coordinate: {
            latitude: latitude,
            longitude: longitude
        },
        image: image,
        canShowCallout: true,
        draggable: true,
        selected: selected,
        lockedToScreen: lockedToScreen // lockedToScreen属性仅对iOS生效
    });
}

let params = {};
// params.removeAllAnnotationMarkers = true // 是否清除当前所有点标记
// params.showAllAnnotationMarkers = true // 是否显示添加的所有点标记
params.annotationMarkers = annotationMarkers;

let newParams = {}
newParams.businessArray = [{
    business: "addAnnotationMarkers", // 业务
    params: params
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 移除所有的点标记

let newParams = {}
newParams.businessArray = [{
    business: "removeAllAnnotationMarkers"
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 显示所有的点标记

let newParams = {}
newParams.businessArray = [{
    business: "showAllAnnotationMarkers"
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 隐藏logo

let newParams = {}
newParams.businessArray = [{
    business: "hideLogo"
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 设置定位精确度,仅支持iOS

let newParams = {}
newParams.businessArray = [{
    business: "setDesiredAccuracy",
    params: {
        desiredAccuracy: "BestForNavigation" // BestForNavigation、Best、NearestTenMeters、HundredMeters、Kilometer、ThreeKilometers
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 是否允许后台定位,仅支持iOS,

let newParams = {}
newParams.businessArray = [{
    business: "allowsBackgroundLocationUpdates"
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 更新点标记坐标

var annotationMarkers = [];
annotationMarkers.push({
    identify: this.identify, // 添加点标记点时候需要添加标识符,更新的时候根据这个标识符来查找
    coordinate: {
            latitude: latitude,
            longitude: longitude
        },
    title: "北京",
    subtitle: "北京是中国的首都",
    image: image2
})
var params = {};
params.annotationMarkers = annotationMarkers;
this.$refs.mapview.addAnnotationMarkers(JSON.stringify(params));

let params = {
    latitude: location.latitude,
    longitude: location.longitude,
    identify: this.identify
}

let newParams = {}
newParams.businessArray = [{
    business: "setAnnotationMarkerCoordinate"
    params: params
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. xxx

  2. 设置点标记旋转移动方向


let params = {}
params.movingDirection = 12.2 // 旋转角度, 如当前角度是0,720表示逆时针旋转2周,-720表示正时针旋转2周
params.identify = "xxx"

let newParams = {}
newParams.businessArray = [{
    business: "setAnnotationMarkerMovingDirection",
    params: params
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. xxx

  2. 设置地图旋转角度(逆时针为正向),暂不支持harmony


let params = {}
params.rotationDegree = 12.2 // 旋转角度, 如当前角度是0,720表示逆时针旋转2周,-720表示正时针旋转2周
params.animated = true // 仅支持iOS
params.duration = 1.0 // 仅支持iOS

let newParams = {}
newParams.businessArray = [{
    business: "setRotationDegree",
    params: params
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 从地图上删除所有的覆盖物(marker,circle,polyline 等对象),但myLocationOverlay(内置定位覆盖物)除外。仅支持Android

let newParams = {}
newParams.businessArray = [{
    business: "clear",
    params: {
        isKeepMyLocationOverlay: true
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}
  1. 从地图上删除标记点

let newParams = {}
newParams.businessArray = [{
    business: "removeAnnonationMarker",
    params: {
        identifys: ["xxx", "xxx"]
    }
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}

接口业务

  • 显示3D地形图(在地图创建前设置),暂不支持harmony

setTerrainEnabled(true)
  • 打开离线地图下载页面,目前仅能使用高德地图自带的UI,暂不支持harmony

toOffineMapPage()

导航

ios、Android导航:


let navi = new UTSAMapNaviCompositeManager()
  • 导航
let params = {}
// 起点,起点不传默认是当前位置
params.start = {
    latitude: 40.080525,
    longitude: 116.603039,
    name: "北京首都机场",
    poiId: "" // 没有poiId可以不传
}

// 终点
params.end = {
    latitude: 39.918058,
    longitude: 116.397026,
    name: "故宫",
    poiId: "B000A8UIN8"
}

// 途径点,没有途径点可以不传
params.way = [{
    latitude: 39.941823,
    longitude: 116.426319,
    name: "北京大学",
    poiId: "B000A816R6",
}]
if(this.isAndroid) {
    // pageType: navi、route
    // navi为直接导航
    // route为路线选择
    params.pageType = "navi" // 
} else {
    params.startNaviDirectly = true // startNaviDirectly参数仅支持iOS
}

// 启动导航
navi.showRoutePlanPage(params, (resp)=>{
    this.naviCallback(resp)
})

// 退出导航
navi.exitRoutePage()

harmony导航: harmony导航通过UI控件来实现

        <!--  #ifdef  APP-HARMONY -->
<embed :style="'width:'+width+'px;height:'+height+'px;'" tag="naviview" :options="options"
    @onevent="onEvent"></embed>
<!--  #endif -->

let paramsModel = {
    appkey: this.harmonyAppId, // 鸿蒙高德的key
    type: "Driver", // Driver、Ride、Walk、EleBike(电动车)、MotorCycle(摩托车类型)
    naviType: "GPS", // NONE、GPS、EMULATOR(模拟导航)、CRUISE(CRUISE)
    start: { // 起点,鸿蒙一定要传起点
        latitude: 39.080525,
        longitude: 116.603039,
        name: "北京首都机场",
        poiId: "B000A28DAE"
    },
    end: { // 终点
        latitude: 39.918058,
        longitude: 116.397026,
        name: "故宫",
        poiId: "B000A8UIN8"
    },
    way: [{ // 途径点
        latitude: 39.941823,
        longitude: 116.426319,
        name: "北京大学",
        poiId: "B000A816R6",
    }],
    routeStrategy: "DRIVING_MULTIPLE_ROUTES_DEFAULT" // 多路径-速度优先+躲避拥堵+距离较短,建议使用该策略,策略值 10

}

let params = {}
params.businessArray = [{
    business: "startNavi", //开启导航
    params: paramsModel
}]

let newParamsStr = this.formatNewParams(params)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
    params: newParamsStr
}

导航事件回调:


onEvent(event) {
    console.log("onEvent:" + JSON.stringify(event))
    // 如需更多导航数据的回调请联系作者
    let detail = event.detail
    let opt = detail.opt
    switch (opt) {
        case "goback": {
            // 用户推出导航
            uni.navigateBack()
        }
        break;
        case "onArriveDestination": {
            // 达到目的地    
        }
        break;
        case "onReCalculateRouteForYaw": {
            // 偏航后准备重新规划路线前的通知回调
        }
        break;
        case "onArrivedWayPoint": {
            // 驾车路径导航到达某个途经点的回调函数
            let wayID = detail.data
        }
        break;
        case "onGpsOpenStatus": {
            // 用户手机位置信息设置是否开启的回调函数。
            let enabled = detail.enabled
        }
        break;
        case "onServiceAreaUpdate": {
            // 服务区信息回调函数
            let enabled = detail.enabled
        }
        break;
        case "onCalculateRouteSuccess": {
            // 路线规划成功回调

        }
        break;
        case "onCalculateRouteFailure": {
            // 路线规划失败回调

        }
        break;
        default:
            break;
    }
}

地图计算工具

  1. 其他坐标系转到高德坐标系,暂不支持harmony

let latitude = 39.989612
 let longitude = 116.480972

// type:
// 0:Baidu
// 1:MapBar
// 2:MapABC
// 3:SoSoMap
// 4:AliYun
// 5:Google
// 6:GPS
let type  = 0 
let position = coordinateConvert(latitude, longitude, type)
  1. 两点间的直线距离计算,暂不支持harmony

let latitude1 = 39.989612
let longitude1 = 116.480972
let latitude2 = 39.990347
let longitude2 = 116.480441
let distance = metersBetweenMapPoints(latitude1, longitude1, latitude2, longitude2)
  1. 判断点是否在圆形内,仅支持ios

let latitude = 39.989612
let longitude = 116.480972
let centerLatitude = 39.990347
let centerLongitude = 116.480441
let radius = 200 // 单位米
let isContains = circleContainsCoordinate(latitude, longitude, centerLatitude, centerLongitude, radius)
  1. 面积计算,仅支持Android

// 左上角和右下角的坐标
let latitude1 = 39.989612
let longitude1 = 116.480972
let latitude2 = 39.990347
let longitude2 = 116.480441
let area = calculateArea(latitude1, longitude1, latitude2, longitude2)

获取地图数据

  1. 获取POI数据

var params = {};
// 搜索关键字,多个关键字用“|”分割
params.keywords = this.keywords;
params.page = 1;
params.offset = 20;
// 仅在通过关键字搜索时进行限制严格按照设置城市搜索
params.cityLimit = true
params.city = "" // POI搜索区域,可以是城市编码也可以是城市名称,也可以传空字符串,空字符串代表全国在全国范围内进行搜索
params.location = {
    latitude: 39.992520,
    longitude: 116.336170
};

// 以下参数仅支持Android和harmony
// 搜索半径,单位米
params.radius = 5000 
// POI搜索类型,下面地址下载POI分类码表,多个类型用“|”分割 可选值:文本分类、分类代码
// https://lbs.amap.com/api/android-sdk/guide/map-data/poi
params.ctgr = "" 
// 返回是否按照距离排序
params.isDistanceSort = true
// 返回是否按照父子关系展示POI
params.requireSubPois = true
// 扩展字段 base表示只返回基础数据,all表示所有数据 ,默认 base
params.extensions = "all"
// 是否对结果进行人工干预,如火车站,原因为POI较为特殊,结果存在人工干预,干预结果优先,所以距离优先的排序未生效 仅周边搜索支
params.isSpecial = true 

// 以下参数仅支持iOS
// 分类,类型,多个类型用“|”分割 可选值:文本分类、分类代码
params.types = ""
// //排序规则, 0-距离排序;1-综合排序, 默认0
params.sortrule = 0
/params.showFieldsType = 0

geoSearch.searchPOI(params, (resp)=>{
    this.showMsg(JSON.stringify(resp))
    // Android/iOS返回的数据结构差异需要各自去解析
    this.showMsg(JSON.stringify(resp))
    var opt = resp.opt
    if(opt == 'onPOISearchSuc') { // 成功

    } else { // 失败
    }
})
  • 输入内容自动提示,目前仅支持Android,iOS请联系作者

import { UTSGeoSearch, UTSInputtips} from "@/uni_modules/wrs-uts-amap"
let inputtips = new UTSInputtips()  

var city = "鄂州市" // 城市名称(如:北京市)或城市编码
var params = {}
params.keyword = this.keywords // 查询关键字
params.city = city // 查询的城市编码 citycode、城市名称(中文或中文全拼)、行政区划代码adcode。设置“”为全国。
params.cityLimit = true // 返回是否严重按照设定城市返回结果。
// params.location = {
//  latitude: 100,
//  longitude: 100
// }
// params.type = "xxx" // 搜索类型的组合,仅支持数字,对照下载页面获取的POI分类表输入。多种类型使用“|”分隔。https://lbs.amap.com/api/webservice/download
inputtips.requestInputtips(params, (resp)=>{
    this.showMsg(JSON.stringify(resp))
    if(resp.code == 1000) { //成功

    }
})
  1. 获取地址描述数据,暂不支持harmony 地理编码(地址转坐标)

var params= {};
params.address = this.address; // 位置
// params.city = "北京" 
geoSearch.geocodeSearch(params, (resp) => {
    this.showMsg(JSON.stringify(resp))
    var opt = resp.opt
    switch (opt){
        // 成功
        case "onGeocodeSearchSuc":

        break;
        // 失败
        case "onSearchFail":
            break;
        default:
            break;
    }
});
  • 逆地理编码(坐标转地址),暂不支持harmony

var params= {};
params.requireExtension = true
params.latitude = parseFloat(this.latitude)
params.longitude = parseFloat(this.longitude)
geoSearch.searchRegeocode(params, (resp)=>{
    this.showMsg(JSON.stringify(resp))
    var opt = resp.opt
    switch (opt){
        // 成功
        case "onReGeocodeSearchSuc":

        break;
        // 失败
        case "onSearchFail":
            break;
        default:
            break;
    }
})

定位


import {
    UTSAMapLocationManager
} from "@/uni_modules/wrs-uts-amap"
let locationManager = new UTSAMapLocationManager()
  • 单次定位

let params = {}
switch (uni.getSystemInfoSync().platform) {
    // android
    case 'android': {
        params.onceLocation = true // 开启单次定位
        params.needAddress = true

    }
    break;
    case 'ios': {
        params.reGeocode = true
    }
    break;
    case 'harmonyos': {
        params.priority = "FIRST_FIX"
        params.scenario = "UNSET"
        params.maxAccuracy = 0
        params.singleLocationTimeout = 3000
        params.allowsBackgroundLocationUpdates = false
        params.locatingWithReGeocode = true
    }
    break;
    default:
        break;
}   

locationManager.requestSingleLocation(params, (resp)=>{
    let location = resp.location
    if (location) {
        this.showMsg("定位成功:" + JSON.stringify(location))
    } else {
        this.showMsg("定位失败:" + JSON.stringify(resp))
    }
})
  • 持续定位

设置定位回调


locationManager.setCallback((resp) => {
    let location = resp.location
    if (location) {
        this.showMsg("位置信息:" + JSON.stringify(location))
    }
})

开始定位


let params = {}
switch (uni.getSystemInfoSync().platform) {
    // android
    case 'android': {
        params.onceLocation = false // 是否开启单次定位
        params.needAddress = true
    }
    break;
    case 'ios': {

    }
    break;
    case 'harmonyos': {
        params.priority = "FIRST_FIX"
        params.scenario = "UNSET"
        params.timeInterval = 2
        params.distanceInterval = 0
        params.maxAccuracy = 20
        params.singleLocationTimeout = 3000
        params.allowsBackgroundLocationUpdates = false
    }
    break;
    default:
        break;
}
locationManager.startUpdatingLocation(params)

停止定位


locationManager.stopUpdatingLocation()
  • 后台定位,鸿蒙的后台定位暂时有兼容性问题 在调用定位接口后,再调用下面接口用于支持后台定位

开始后台定位


var params = {}
switch (uni.getSystemInfoSync().platform) {
    // android
    case 'android': {
        params.notificationId = 2001
        params.channelId = "com.wrs.amap"
        params.name = "后台定位"
        params.importance = 5
        params.enableLights = true
        params.showBadge = true
        params.contentTitle = "定位"
        params.contentText = "持久定位"

    }
    break;
    case 'ios': {

    }
    break;
    case 'harmonyos': {
        // checkAccessPermission('ohos.permission.APPROXIMATELY_LOCATION', (resp) => {
        //  let granted = resp.granted
        //  if (granted) {
        //      locationManager.startContinuousTask()
        //  } else {
        //      this.showMsg("checkAccessPermission resp:" + JSON.stringify(resp))
        //  }
        // })
    }
    break;
}
locationManager.enableBackgroundLocation(params)

停止后台定位

                let params = {}
switch (uni.getSystemInfoSync().platform) {
    // android
    case 'android': {
        // 是否已经启动后台定位,如果已经启动后台定位,当app切换到前台时,把后台定位关闭
        params.clearNotifiction = true // 是否移除通知栏

    }
    break;
    case 'ios': {

    }
    break;
    case 'harmonyos': {
        // checkAccessPermission('ohos.permission.APPROXIMATELY_LOCATION', (resp) => {
        //  let granted = resp.granted
        //  if (granted) {
        //      locationManager.startContinuousTask()
        //  } else {
        //      this.showMsg("checkAccessPermission resp:" + JSON.stringify(resp))
        //  }
        // })
    }
    break;
}
locationManager.disableBackgroundLocation(params)
    import {
    getAppId,
    toOffineMapPage,
    requestPermission,
    updatePrivacyShow,
    updatePrivacyAgree
} from "@/uni_modules/wrs-uts-amapview"

获取AppId,仅支持harmony

let appId = getAppId()

请求鸿蒙定位权限


let permission = ['ohos.permission.APPROXIMATELY_LOCATION', 'ohos.permission.LOCATION']
requestPermission(permission, (resp) => {
    let authResults = resp.authResults 
    let length  = authResults.length
    for(let i = 0; i < length; i ++) {
        let result = authResults[i]
        if(result == 0) {
            console.log("用户已经授权")
        } else {
            console.log("用户没有授权")
        }
    }
    console.log("requestPermission resp:" + JSON.stringify(resp))
})

隐私、权限声明

1. 本插件需要申请的系统权限列表:

定位、读写、Wi-Fi

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件使用的 高德地图 SDK会采集数据,详情可参考:https://lbs.amap.com/

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率: