【问题标题】:custom icon from url, not from assets - nativescript google maps ios来自 url 的自定义图标,而不是来自资产的自定义图标 - nativescript google maps ios
【发布时间】:2020-05-07 04:29:54
【问题描述】:

我尝试了很多,但没有成功找到一种从 url 显示标记图标的方法。

 addMarker(mark, index): void {
    const marker = new Marker();
    marker.position = Position.positionFromLatLng(mark.latitude, mark.longitude);
    marker.icon = 'iconsdb.com/icons/preview/red/map-marker-2-xxl.png'; // default pin
    this.mapView.addMarker(marker);
 }

对资产中的图标图像使用this 工作正常。现在我将图标存储在云端,我需要根据记录使用它们。

【问题讨论】:

    标签: ios google-maps-markers nativescript-angular


    【解决方案1】:

    由于从资产加载图像可以使用 ImageSource,我相信您应该能够对来自 URL 的图像执行类似的操作。另见documentation

    ImageSource 有一个您可以调用的“fromUrl”。所以这应该对你有用(从你的链接问题中借用部分代码)

     let imgSrc = new ImageSource();
     imgSrc.fromUrl("iconsdb.com/icons/preview/red/map-marker-2-xxl.png");
    
     let image = new Image();
     image.imageSource = imgSrc;
    
     marker.icon = image;
    

    您可能应该cache 图像,这样它就不会被下载 x 次。

    【讨论】:

      猜你喜欢
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 2016-06-02
      • 1970-01-01
      • 2017-03-05
      • 2013-09-27
      相关资源
      最近更新 更多