HarmonyOS 地图添加marker

地图添加marker以后,title不显示,具体是什么原因。

HarmonyOS
2024-12-19 15:33:23
791浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

参考demo:

import { MapComponent, mapCommon, map } from '@kit.MapKit';
import { AsyncCallback } from '@kit.BasicServicesKit';
@Entry
@Component
struct MarkerDemo {
  private mapOptions?: mapCommon.MapOptions;
  private mapController?: map.MapComponentController;
  private callback?: AsyncCallback<map.MapComponentController>;
  private marker?: map.Marker;

  aboutToAppear(): void {
    // 地图初始化参数
    this.mapOptions = {
      position: {
        target: {
          latitude: 31.984410259206815,
          longitude: 118.76625379397866
        },
        zoom: 15
      }
    };
    this.callback = async (err, mapController) => {
      if (!err) {
        this.mapController = mapController;
        // Marker初始化参数
        let markerOptions: mapCommon.MarkerOptions = {
          position: {
            latitude: 31.984410259206815,
            longitude: 118.76625379397866
          },
          rotation: 0,
          visible: true,
          zIndex: 0,
          alpha: 1,
          anchorU: 0.5,
          anchorV: 1,
          clickable: true,
          draggable: true,
          flat: false
        };
        // 创建Marker
        this.marker = await this.mapController.addMarker(markerOptions);
        // 设置标记可拖拽
        this.marker.setDraggable(true);
        // 设置标记锚点
        this.marker.setMarkerAnchor(1.0, 1.0);
        // 设置信息窗的标题
        this.marker.setTitle('南京');
        // 设置信息窗的子标题
        this.marker.setSnippet('华东地区');
        // 设置信息窗的锚点位置
        this.marker.setInfoWindowAnchor(1, 1);
        // 设置信息窗可见
        this.marker.setInfoWindowVisible(true);
      }
    };
  }
  build() {
    Stack() {
      Column() {
        MapComponent({ mapOptions: this.mapOptions, mapCallback: this.callback });
      }.width('100%')
    }.height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
分享
微博
QQ
微信
回复
2024-12-19 18:07:51
相关问题
HarmonyOS 添加marker
548浏览 • 1回复 待解决
HarmonyOS 地图自定义marker
760浏览 • 1回复 待解决
HarmonyOS 地图中是否支持海量marker
1239浏览 • 0回复 待解决
HarmonyOS 地图中如何渲染多个marker
867浏览 • 1回复 待解决
HarmonyOS 地图组件里marker固定位置
662浏览 • 1回复 待解决
HarmonyOS 地图组件如何添加自定义UI
575浏览 • 1回复 待解决
HarmonyOS marker无设置图片大小问题
629浏览 • 1回复 待解决
HarmonyOS 离线地图
881浏览 • 1回复 待解决
HarmonyOS 显示不出地图
507浏览 • 1回复 待解决
HarmonyOS 地图相关问题
1548浏览 • 1回复 待解决
HarmonyOS 地图无法展示
792浏览 • 1回复 待解决