代码之家  ›  专栏  ›  技术社区  ›  Hamidreza Sadegh

反应本地映射删除标记

  •  1
  • Hamidreza Sadegh  · 技术社区  · 7 年前

    我在我的项目中使用了react本地映射。它工作得很好。然后我在Project中添加了一些新组件,当我从地图中删除自定义标记时,会突然出现红色屏幕:
    移除标记:尝试在空对象引用上调用虚拟方法“void com.google.android.gms.maps.model.seticon(com.google.android.gms.maps.model.bitmapdescription)”。 enter image description here

    1 回复  |  直到 7 年前
        1
  •  0
  •   I'm not human    7 年前

    您有两种选择:

    第一个选项 (最简单但不会给你最好的结果)

    使用默认标记:

    <MapView.Marker
                    identifier="DestMarker"
                    title={SCHEDULED_LABEL}
                    description={this.props.region.address}
                    coordinate={{
                        latitude: this.props.region.latitude,
                        longitude: this.props.region.longitude,
                    }}
                />
    

    第二种选择 编辑反应本地映射库

    去:

    里面 节点\模块 改变这一行代码

    marker.setIcon(getIcon());

    为此:

    if (marker != null) {
      marker.setIcon(getIcon());
    }
    

    你的任务完成了!

    注意:请记住重新安装应用程序以查看您的更改。

    推荐文章