You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native集成Google Maps时react-native-map报AIRMapPolygon坐标错误

报错原因

该报错由Polygon组件的coordinates属性格式不符合react-native-maps的要求导致:

  • 注意和Marker组件区分:Marker是点标记组件,用单数形式的coordinate属性接收单个坐标对象;Polygon是面状多边形覆盖物组件,需要用复数形式的coordinates属性,传入由至少3个经纬度点组成的数组,按顺序定义多边形的各个顶点才能渲染出闭合图形
  • 你当前给Polygon传入的是单个对象,还错误加入了仅用于地图区域定位的latitudeDelta、longitudeDelta字段,原生端渲染多边形组件时无法解析该属性值,就会抛出属性更新失败的错误。
修复方案

根据实际业务需求调整代码即可:

  1. 如果你需要在地图上绘制多边形覆盖物:将coordinates属性替换为坐标点数组,每个坐标点仅保留latitude、longitude两个字段,修正后的完整代码参考如下:
<MapView
  provider={PROVIDER_GOOGLE}
  style={styles.map}
  initialRegion={{
    latitude: region.latitude,
    longitude: region.longitude,
    latitudeDelta: region.latitudeDelta,
    longitudeDelta: region.longitudeDelta,
  }}
>
  <Marker
    coordinate={{
      latitude: region.latitude,
      longitude: region.longitude,
    }}
    draggable={true}
  >
    <Callout>
      <Text>Callout</Text>
    </Callout>
  </Marker>
  {/* 修正后的Polygon组件 */}
  <Polygon
    coordinates={[
      { latitude: 24.591489, longitude: 73.722545 },
      { latitude: 24.591989, longitude: 73.722545 },
      { latitude: 24.591989, longitude: 73.723045 },
    ]}
    fillColor="rgba(0, 150, 255, 0.3)"
    strokeColor="rgba(0,150,255,1)"
    strokeWidth={2}
  />
</MapView>
  1. 如果你只是需要标记单个坐标点:直接删除错误编写的Polygon组件即可,你代码中已编写的Marker组件已经实现了单点标记的功能,不需要额外添加Polygon组件。

内容的提问来源于stack exchange,提问作者Nishant Paliwal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 15:36:26