更新记录
1.0.2(2026-08-27)
初始化
1.0.0(2024-12-10)
初始化,具体功能用法 ,请参考附带demo
平台兼容性
uni-app(4.52)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | × | × | × | √ | 5.0 | √ | × |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | × | × | × |
uni-app x(4.82)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| × | × | 5.0 | √ | √ | × |
xtf-baidumapview
百度地图 UTS 组件,提供 uni-app x uvue 标准模式组件和传统 uni-app nvue 兼容模式组件。
| 组件标签 | 项目类型 | Android | iOS | 鸿蒙 | 能力范围 |
|---|---|---|---|---|---|
xtf-baidumapview |
uni-app x uvue |
支持 | 支持 | 支持 | 标准模式,完整 API。 |
xtf-baidumapview-nvue |
传统 uni-app nvue |
支持 | 支持 | 不支持 | 兼容模式,地图、Marker、定位、城市 POI、路线。 |
nvue 组件不支持鸿蒙,也不能用于 uni-app x Vapor 模式。由于 Weex 引擎限制,nvue 的公开命令无同步返回值,所有结果必须监听事件。
目录
配置百度地图 Key
先在百度地图开放平台为每个 App 平台创建对应类型的 Key。Android Key 必须匹配最终包名和签名 SHA1;iOS Key 必须匹配 Bundle ID;鸿蒙 Key 必须匹配鸿蒙应用配置。不要在不同平台共用不匹配的 Key。
uvue 配置
推荐在 apiKeys 传入各平台 Key。组件按当前运行平台自动选择对应字段:Android 读取 android,iOS 读取 ios,鸿蒙读取 harmony,对应字段为空才读取 defaultKey。
<xtf-baidumapview
class="map-view"
:api-keys="{
defaultKey: null,
android: 'Android 百度地图 AK',
ios: 'iOS 百度地图 AK',
harmony: 'Harmony 百度地图 AK'
}"
/>
也可以为单个平台传入 apiKey:
<xtf-baidumapview class="map-view" api-key="当前平台的百度地图 AK" />
Key 解析优先级为:apiKey、apikey、apiKeys.当前平台、apiKeys.defaultKey、options.apiKey、options.apiKeys.当前平台、options.apiKeys.defaultKey。Android 在创建地图前会显式完成隐私同意和 SDK 初始化;缺少 Key 会触发 error,code 为 xtf-baidumapview:sdk-not-configured。
nvue 配置
nvue 的 Android 和 iOS 都应在组件创建时传入 api-key,Android 需要使用该 Key 初始化 SDK:
<xtf-baidumapview-nvue class="map-view" api-key="Android 或 iOS 的百度地图 AK" />
在 App.uvue 全局初始化
如果项目只使用组件 apiKey/apiKeys,不必在 App.uvue 重复配置。需要在应用启动阶段提前校验、记录或初始化 Key 时,可采用下列方式。Android 必须在用户同意隐私协议后再调用初始化;组件自身也会执行一次幂等初始化。
<script setup lang="uts">
// #ifdef APP-ANDROID
import { configureXtfBaiduMapSdk } from '@/uni_modules/xtf-baidumapview'
// #endif
// #ifdef APP-IOS
import { setXtfBaiduMapApiKey } from '@/uni_modules/xtf-baidumapview/utssdk/app-ios/config.uts'
// #endif
import { demoMapApiKeys } from '@/pages/demo/shared/demo-data.uts'
function initializeBaiduMapInApp() {
// #ifdef APP-ANDROID
const androidKey = demoMapApiKeys.android
if (androidKey != null && androidKey.length > 0) {
const status = configureXtfBaiduMapSdk(androidKey, true, 'BD09LL')
console.log('[xtf-baidumapview] Android SDK state=' + (status['state'] as string))
}
// #endif
// #ifdef APP-IOS
setXtfBaiduMapApiKey(demoMapApiKeys.ios)
// #endif
// #ifdef APP-HARMONY
// 鸿蒙没有全局 Key 初始化 API。请在每个 xtf-baidumapview 组件上
// 传入 api-key 或 api-keys.harmony,组件创建时会调用 HAR 的 setApiKey。
// #endif
}
onLaunch(() => {
// Android: 放在用户已同意隐私协议后的回调中执行。
initializeBaiduMapInApp()
})
</script>
示例中的 demoMapApiKeys 可替换为项目自己的配置文件。建议只在该配置文件保存 Key,页面组件统一传 :api-keys="mapApiKeys":
export const mapApiKeys : XtfBaiduMapApiKeys = {
defaultKey: null,
android: 'Android AK',
ios: 'iOS AK',
harmony: 'Harmony AK'
}
uvue 快速开始
<template>
<view class="page-root">
<xtf-baidumapview
ref="mapRef"
class="map-view"
:api-keys="apiKeys"
:options="mapOptions"
:markers="markers"
@load="onLoad"
@error="onError"
@markerclick="onMarkerClick"
@poichange="onPoiChange"
@routechange="onRouteChange"
/>
</view>
</template>
<script setup lang="uts">
import { XtfBaiduMapApiKeys, XtfBaiduMapInitOptions, XtfBaiduMarker } from '@/uni_modules/xtf-baidumapview/utssdk/interface.uts'
const apiKeys : XtfBaiduMapApiKeys = {
defaultKey: null,
android: 'Android AK',
ios: 'iOS AK',
harmony: 'Harmony AK'
}
const mapOptions : XtfBaiduMapInitOptions = {
apiKey: null, apiKeys: null, center: { latitude: 39.914935, longitude: 116.403119 },
zoom: 12, minZoom: 3, maxZoom: 21, overlook: 0, rotation: 0, mapType: 'normal',
trafficEnabled: false, buidingEnabled: true, heatMapEnabled: false, indoorEnabled: false,
indoorPoiEnabled: false, showScaleControl: true, showZoomControl: true, showCompass: false,
showBuildings: true, locationEnabled: false, locationFollowMode: 'normal', logoPosition: 'left-bottom',
mapLanguage: 'zh', customMapStylePath: null, customMapStyleId: null, padding: null,
limitBounds: null, clusterEnabled: false, clusterGridSize: 60, gestures: null, locationOptions: null
}
const markers = ref<Array<XtfBaiduMarker>>([])
const mapRef = ref<XtfBaidumapviewComponentPublicInstance | null>(null)
function onLoad() { mapRef.value?.moveToLocation(39.914935, 116.403119, 14) }
function onError(detail : UTSJSONObject) { console.error(detail['code'], detail['message']) }
function onMarkerClick(detail : UTSJSONObject) { console.log(detail['markerId']) }
function onPoiChange(detail : UTSJSONObject) { console.log(detail) }
function onRouteChange(detail : UTSJSONObject) { console.log(detail) }
</script>
<style>
.page-root { flex: 1; display: flex; flex-direction: column; }
.map-view { flex: 1; }
</style>
所有公开方法应在 load 后通过 mapRef.value 调用。
uvue 参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
apiKey |
string |
'' |
单平台 Key,优先级最高。 |
apikey |
string |
'' |
apiKey 兼容别名。 |
apiKeys |
XtfBaiduMapApiKeys \| null |
null |
defaultKey/android/ios/harmony 多端 Key。 |
options |
XtfBaiduMapInitOptions |
{} |
地图初始状态和功能开关。 |
markers |
XtfBaiduMarker[] |
[] |
标记点集合。 |
polylines |
XtfBaiduPolyline[] |
[] |
折线集合。 |
polygons |
XtfBaiduPolygon[] |
[] |
多边形集合。 |
circles/arcs/dots/texts |
对应类型数组 | [] |
圆、弧线、点、文本集合。 |
groundOverlays/textPathOverlays/tileOverlays |
对应类型数组 | [] |
图片、文字路径、瓦片集合。 |
multiPointOverlays/heatMapOverlays/hexagonOverlays |
对应类型数组 | [] |
海量点、热力、六边形图层。 |
building3DOverlays/prismOverlays/model3DOverlays |
对应类型数组 | [] |
3D 覆盖物。 |
traceOverlays/track3DOverlays |
对应类型数组 | [] |
轨迹与 3D 轨迹。 |
locationData |
XtfBaiduLocationData \| null |
null |
自定义定位数据。 |
常用类型参数
const point : XtfBaiduPoint = { latitude: 39.914935, longitude: 116.403119 }
const bounds : XtfBaiduBounds = {
southwest: { latitude: 39.8, longitude: 116.2 },
northeast: { latitude: 40.0, longitude: 116.5 }
}
const marker : XtfBaiduMarker = {
id: 'tiananmen', position: point, title: '天安门', snippet: '北京', iconPath: null,
anchorX: 0.5, anchorY: 1, rotation: 0, alpha: 1, zIndex: 1, draggable: false,
flat: false, perspective: false, animateType: null, joinCollision: false,
collision: false, fixedScreenPosition: null
}
XtfBaiduMapInitOptions 的主要字段:center、zoom、minZoom、maxZoom、overlook、rotation、mapType、trafficEnabled、buidingEnabled、heatMapEnabled、indoorEnabled、indoorPoiEnabled、showScaleControl、showZoomControl、showCompass、locationEnabled、locationFollowMode、logoPosition、mapLanguage、padding、limitBounds、clusterEnabled、clusterGridSize、gestures、locationOptions。注意字段名是 buidingEnabled,这是现有接口的固定拼写。
XtfBaiduGestureOptions 包含:scrollEnabled、overlookEnabled、zoomEnabled、rotateEnabled、doubleClickZoomEnabled、twoTouchClickZoomEnabled、enlargeCenterWithDoubleClickEnabled、flingEnabled,全部为 boolean。
uvue 事件
事件参数均为 UTSJSONObject。所有原生事件会先发出 nativeevent,然后根据 detail['type'] 发出具体事件。
| 事件 | 说明 | 常用字段 |
|---|---|---|
load |
地图完成加载 | type。 |
error |
Key、权限、参数、原生能力异常 | type/code/message。 |
mapstatuschange |
状态开始、变化、结束 | phase/source/changeId/latitude/longitude/zoom/rotation/overlooking。 |
mapclick/mappoiclick |
地图或 POI 点击 | 经纬度,POI 另含 name。 |
markerclick/multipointclick/clusterclick |
覆盖物点击 | markerId 或覆盖物 ID。 |
locationchange |
定位更新 | latitude/longitude/accuracy/direction/city/address。 |
routechange |
路线结果 | status/code/message/mode/summary/polylinePoints。 |
geocodechange/poichange/searchchange |
检索结果 | status/code/message/payload。 |
offlinechange |
离线状态 | offlineType/state/cityID/cityName/ratio/status。 |
snapshot/distance/coordinate-converted/coordinate-type-changed/spatial-result |
工具结果 | 对应工具的结果字段。 |
tracechange/trackanimationchange/favoritechange/navigationchange/shareurlchange |
轨迹、收藏、导航、分享状态 | action/status/code/message。 |
uvue 方法
下列示例中 map 表示 mapRef.value!,p1/p2/p3 表示 XtfBaiduPoint。
地图配置与视野
| 方法 | 参数 | 示例 |
|---|---|---|
setApiKey |
string \| null |
map.setApiKey('AK') |
setOptions |
XtfBaiduMapInitOptions \| null |
map.setOptions(mapOptions) |
setMapType |
string |
map.setMapType('satellite') |
setMapLanguage |
string |
map.setMapLanguage('zh') |
setTrafficEnabled |
boolean |
map.setTrafficEnabled(true) |
setHeatMapEnabled |
boolean |
map.setHeatMapEnabled(true) |
setBuildingsEnabled |
boolean |
map.setBuildingsEnabled(true) |
setIndoorEnabled |
boolean |
map.setIndoorEnabled(true) |
setIndoorPoiEnabled |
boolean |
map.setIndoorPoiEnabled(true) |
setLocationEnabled |
boolean |
map.setLocationEnabled(true) |
setLocationFollowMode |
string |
map.setLocationFollowMode('follow') |
setShowScaleControl |
boolean |
map.setShowScaleControl(true) |
setShowZoomControl |
boolean |
map.setShowZoomControl(true) |
setShowCompass |
boolean |
map.setShowCompass(true) |
setLogoPosition |
string |
map.setLogoPosition('left-bottom') |
setPadding |
XtfBaiduPadding \| null |
map.setPadding({ left: 20, top: 20, right: 20, bottom: 20 }) |
setPaddingJson |
JSON 字符串或 null |
map.setPaddingJson('{"left":0,"top":0,"right":0,"bottom":0}') |
setGestures |
XtfBaiduGestureOptions \| null |
map.setGestures({ scrollEnabled:true, overlookEnabled:true, zoomEnabled:true, rotateEnabled:true, doubleClickZoomEnabled:true, twoTouchClickZoomEnabled:true, enlargeCenterWithDoubleClickEnabled:true, flingEnabled:true }) |
setGesturesJson |
JSON 字符串 | map.setGesturesJson(gesturesJson) |
setMapBounds |
XtfBaiduBounds |
map.setMapBounds(bounds) |
setMapBoundsJson |
JSON 字符串 | map.setMapBoundsJson(boundsJson) |
setMapStatusLimits |
XtfBaiduBounds |
map.setMapStatusLimits(bounds) |
setMapStatusLimitsJson |
JSON 字符串 | map.setMapStatusLimitsJson(boundsJson) |
moveToLocation |
(point, zoom) 或 (lat,lng,zoom) |
map.moveToLocation(39.914935, 116.403119, 15) |
moveToLocationWithZoom |
lat,lng,zoom |
map.moveToLocationWithZoom(39.9, 116.4, 12) |
setClusterEnabled |
boolean |
map.setClusterEnabled(true) |
setClusterGridSize |
number |
map.setClusterGridSize(60) |
覆盖物
| 方法 | 参数 | 示例 |
|---|---|---|
setMarkers |
XtfBaiduMarker[] \| null |
map.setMarkers([marker]) |
replaceMarkers |
XtfBaiduMarker[] \| null |
map.replaceMarkers([marker]) |
addMarkers |
XtfBaiduMarker[] \| null |
map.addMarkers([marker]) |
setPolylines |
XtfBaiduPolyline[] \| null |
map.setPolylines([{ id:'line', points:[p1,p2], color:'#1677ff', width:6, zIndex:1, dottedLine:false, geodesic:false, focus:false, keepScale:false, thined:false, textureList:null }]) |
setPolygons |
XtfBaiduPolygon[] \| null |
map.setPolygons([polygon]) |
setCircles |
XtfBaiduCircle[] \| null |
map.setCircles([circle]) |
setArcs |
XtfBaiduArc[] \| null |
map.setArcs([arc]) |
setDots |
XtfBaiduDot[] \| null |
map.setDots([dot]) |
setTexts |
XtfBaiduText[] \| null |
map.setTexts([text]) |
setGroundOverlays |
XtfBaiduGroundOverlay[] \| null |
map.setGroundOverlays([ground]) |
setTextPathOverlays |
XtfBaiduTextPathOverlay[] \| null |
map.setTextPathOverlays([textPath]) |
setTileOverlays |
XtfBaiduTileOverlay[] \| null |
map.setTileOverlays([tile]) |
setMultiPointOverlays |
XtfBaiduMultiPointOverlay[] \| null |
map.setMultiPointOverlays([multiPoint]) |
setHeatMapOverlays |
XtfBaiduHeatMapOverlay[] \| null |
map.setHeatMapOverlays([heatMap]) |
setBuilding3DOverlays |
XtfBaiduBuilding3DOverlay[] \| null |
map.setBuilding3DOverlays([building3D]) |
setPrismOverlays |
XtfBaiduPrismOverlay[] \| null |
map.setPrismOverlays([prism]) |
setTraceOverlays |
XtfBaiduTraceOverlay[] \| null |
map.setTraceOverlays([trace]) |
setTrack3DOverlays |
XtfBaiduTrack3DOverlay[] \| null |
map.setTrack3DOverlays([track3D]) |
setModel3DOverlays |
XtfBaiduModel3DOverlay[] \| null |
map.setModel3DOverlays([model3D]) |
setHexagonOverlays |
XtfBaiduHexagonOverlay[] \| null |
map.setHexagonOverlays([hexagon]) |
removeOverlays |
XtfBaiduOverlayRemoveOptions \| null |
map.removeOverlays({ markerIds:['tiananmen'], polylineIds:null, polygonIds:null, circleIds:null, arcIds:null, dotIds:null, textIds:null, groundOverlayIds:null, textPathIds:null, tileOverlayIds:null, multiPointIds:null, heatMapIds:null, building3DIds:null, prismIds:null, traceIds:null, track3DIds:null, model3DIds:null, hexagonIds:null }) |
showInfoWindow |
XtfBaiduInfoWindowOptions |
map.showInfoWindow({ markerId:'tiananmen', title:'天安门', snippet:'北京', yOffset:0 }) |
hideInfoWindow |
无 | map.hideInfoWindow() |
定位、路线和轨迹动画
| 方法 | 参数 | 示例 |
|---|---|---|
updateLocationData |
XtfBaiduLocationData \| null |
map.updateLocationData(locationData) |
startLocation |
无 | map.startLocation() |
stopLocation |
无 | map.stopLocation() |
searchRoute |
XtfBaiduRouteSearchRequest |
map.searchRoute({ mode:'driving', start:{ city:null, name:null, point:p1 }, end:{ city:null, name:null, point:p2 }, showPolyline:true, zoomToSpan:true, drivingPolicy:null, trafficPolicy:null }) |
clearRoute |
无 | map.clearRoute() |
startPolylineTrackAnimation |
XtfBaiduPolylineTrackAnimationOptions |
map.startPolylineTrackAnimation({ polylineId:'line', trackPath:[p1,p2], duration:2000, fromRadio:null, toRadio:null, fromPoint:null, toPoint:null, forwardStyles:null, backwardStyles:null, autoStart:true }) |
setPolylineTrackAnimationPosRadio |
polylineId,fromRadio,toRadio |
map.setPolylineTrackAnimationPosRadio('line', 0, 0.5) |
setPolylineTrackAnimationPos |
polylineId,fromPoint,toPoint |
map.setPolylineTrackAnimationPos('line', null, p2) |
setPolylineTrackAnimationDuration |
polylineId,duration |
map.setPolylineTrackAnimationDuration('line', 3000) |
clearPolylineTrackAnimation |
polylineId |
map.clearPolylineTrackAnimation('line') |
检索服务
| 方法 | 参数 | 示例 |
|---|---|---|
geocode |
{city,address} |
map.geocode({ city:'北京', address:'天安门' }) |
reverseGeocode |
{point,radius,pageNum,newVersion} |
map.reverseGeocode({ point:p1, radius:1000, pageNum:0, newVersion:1 }) |
searchPoiInCity |
{city,keyword,pageNum,cityLimit,scope,abroad} |
map.searchPoiInCity({ city:'北京', keyword:'医院', pageNum:0, cityLimit:false, scope:1, abroad:false }) |
searchPoiNearby |
{keyword,center,radius,pageNum,radiusLimit,scope,abroad} |
map.searchPoiNearby({ keyword:'咖啡', center:p1, radius:2000, pageNum:0, radiusLimit:false, scope:1, abroad:false }) |
searchSuggestion |
{city,keyword} |
map.searchSuggestion({ city:'北京', keyword:'天安门' }) |
searchAoi |
{points} |
map.searchAoi({ points:[p1,p2,p3] }) |
searchDistrict |
{cityName,districtName} |
map.searchDistrict({ cityName:'北京市', districtName:'朝阳区' }) |
searchIndoorPoi |
{keyword} |
map.searchIndoorPoi({ keyword:'洗手间' }) |
searchBusLine |
{city,keyword} |
map.searchBusLine({ city:'北京', keyword:'1路' }) |
searchRecommendStop |
{point} |
map.searchRecommendStop({ point:p1 }) |
searchWeather |
{districtID} |
map.searchWeather({ districtID:'110100' }) |
searchBuilding |
{point} |
map.searchBuilding({ point:p1 }) |
searchXtfBaiduMap |
XtfBaiduSearchRequest, callback,返回请求 ID |
const id = map.searchXtfBaiduMap({ type:'city-poi', city:'北京', keyword:'地铁', pageNum:0, cityLimit:false, scope:1 } as UTSJSONObject, (result : UTSJSONObject) => { console.log(result) }) |
cancelXtfBaiduSearch |
requestId:number,返回是否取消成功 |
map.cancelXtfBaiduSearch(id) |
统一检索 type 支持:geocode、reverse-geocode、city-poi、nearby-poi、bounds-poi、poi-detail、suggestion、aoi、district、indoor-poi、bus-line、recommend-stop、weather、building。结果字段固定为 requestId/type/status/code/message/payload。
离线、导航、工具和释放
| 方法 | 参数和返回 | 示例 |
|---|---|---|
getOfflineHotCities |
返回 XtfBaiduOfflineCity[] |
const cities = map.getOfflineHotCities() |
getOfflineCityList |
返回 XtfBaiduOfflineCity[] |
const cities = map.getOfflineCityList() |
searchOfflineCity |
keyword:string,返回城市数组 |
map.searchOfflineCity('北京') |
getOfflineUpdateList |
返回 XtfBaiduOfflineUpdate[] |
map.getOfflineUpdateList() |
startOffline |
cityId:number,返回 boolean |
map.startOffline(131) |
pauseOffline |
cityId:number,返回 boolean |
map.pauseOffline(131) |
removeOffline |
cityId:number,返回 boolean |
map.removeOffline(131) |
updateOffline |
cityId:number,返回 boolean |
map.updateOffline(131) |
importOfflineData |
无,返回 number |
map.importOfflineData() |
openNavigation |
XtfBaiduOpenNavigationOptions |
map.openNavigation({ mode:'driving', start:planStart, end:planEnd, appScheme:null, appName:null, isSupportWeb:true, transitPolicy:null }) |
shareLocation |
XtfBaiduLocationShareOptions |
map.shareLocation({ point:p1, title:'当前位置', snippet:null }) |
exec |
XtfBaiduMapCommand |
map.exec({ type:'command', payload:null }) |
execJson |
JSON 字符串 | map.execJson('{"type":"command","payload":null}') |
snapshot |
文件名或 null |
map.snapshot('map.png') |
snapshotFile |
文件名或 null |
map.snapshotFile('map.png') |
destroy |
无 | map.destroy() |
nvue 快速开始
<template>
<div class="page-root">
<xtf-baidumapview-nvue
ref="map"
class="map-view"
api-key="当前平台 AK"
:location-enabled="true"
:markers="markers"
@load="onLoad"
@error="onError"
@locationchange="onLocationChange"
@poichange="onPoiChange"
@routechange="onRouteChange"
/>
</div>
</template>
<script>
export default {
data() {
return { markers: [{ id: 'home', latitude: 39.914935, longitude: 116.403119, draggable: false, visible: true }] }
},
methods: {
onLoad() { this.$refs.map.startLocation() },
onError(event) { console.error(event) },
onLocationChange(event) { console.log(event) },
onPoiChange(event) { console.log(event) },
onRouteChange(event) { console.log(event) },
search() { this.$refs.map.searchPoiInCity({ city:'北京', keyword:'医院', pageNum:0, cityLimit:false }) },
route() { this.$refs.map.searchRoute({ mode:'driving', start:{ point:{ latitude:39.9, longitude:116.4 } }, end:{ point:{ latitude:39.91, longitude:116.41 } }, showPolyline:true, zoomToSpan:true, drivingPolicy:null, trafficPolicy:null }) }
}
}
</script>
<style>
.page-root { flex: 1; }
.map-view { width: 750rpx; height: 600rpx; }
</style>
nvue 参数、事件和方法
| 项目 | 名称 | 类型、说明和示例 |
|---|---|---|
| 参数 | apiKey / apikey |
string,apiKey 优先。api-key="AK"。 |
| 参数 | locationEnabled |
boolean。:location-enabled="true"。 |
| 参数 | markers |
Android 使用 {id,latitude,longitude,draggable?,visible?}[];iOS 可使用完整 Marker 对象。 |
| 方法 | setMarkers(markers) |
无同步返回。this.$refs.map.setMarkers([{ id:'a', latitude:39.9, longitude:116.4 }])。 |
| 方法 | startLocation() |
无同步返回,监听 locationchange。this.$refs.map.startLocation()。 |
| 方法 | stopLocation() |
无同步返回。this.$refs.map.stopLocation()。 |
| 方法 | searchPoiInCity(request) |
参数 {city,keyword,pageNum?,cityLimit?},监听 poichange。 |
| 方法 | searchRoute(request) |
参数 {mode,start,end,showPolyline,zoomToSpan,drivingPolicy,trafficPolicy},监听 routechange。 |
| 事件 | load/error/nativeevent |
地图加载、错误、全部原生事件。 |
| 事件 | locationchange/mapclick/mappoiclick/markerclick/mapstatuschange |
定位与地图交互。 |
| 事件 | poichange/routechange |
POI 与路线异步结果。 |
nvue Android 事件参数是 Map<string, any>;iOS 页面建议以 UniEvent 接收。两端均先触发 nativeevent,再触发具体事件。不要期待 nvue 方法返回数组、布尔值、请求 ID 或 Promise。
平台差异和限制
| 能力 | Android uvue | iOS uvue | 鸿蒙 uvue | Android/iOS nvue |
|---|---|---|---|---|
| 标准地图和 Marker | 支持 | 支持 | 支持 | 支持。 |
| 定位、城市 POI、路线 | 支持 | 支持 | 支持范围受 SDK 限制 | 支持,结果使用事件。 |
| 高级覆盖物、快照、导航、分享、统一搜索 | 支持范围取决于 SDK | 支持范围取决于 SDK | 部分能力不支持 | 不提供。 |
| 离线地图 | 支持 | 支持,离线包导入不支持 | 不支持 | 不提供。 |
| 组件模式 | 标准模式 | 标准模式 | 标准模式 | 兼容模式,不支持鸿蒙。 |
| 返回值 | 可同步返回离线列表、布尔值、请求 ID | 同左 | 同左但未支持能力会报错 | 不支持同步返回,只监听事件。 |
使用前请在真机验证 Key、包名、签名、定位权限和 SDK 服务权限。对于未支持能力,组件会通过 error 事件返回 xtf-baidumapview:not-supported 或对应错误码;不要把空数组、false、-1 误判为业务成功。

收藏人数:
购买源码授权版(
试用
使用 HBuilderX 导入示例项目
赞赏(0)
下载 13417
赞赏 75
下载 12644692
赞赏 1952
赞赏
京公网安备:11010802035340号