【问题标题】:Can't show Polygon from ReactNativeMaps无法从 ReactNativeMaps 显示多边形
【发布时间】:2019-02-21 17:06:46
【问题描述】:

我无法正确查看多边形。 我认为这是因为从我的 API 我收到了一组对象..

这是我的代码

<MapView.Polygon
  coordinates={poligonofinale}
  strokeColor="#000"
  fillColor="rgba(255,0,0,0.5)"
  strokeWidth={3}/>

我的坐标变量是

const poligonofinale = this.state.poligono.map(poligono => {
   let test = poligono["poligono"][0]
   return test.coordinates;
});

在 poligonofinale 中做一个 console.log 我明白了

Array [
Array [
    Object {
        "latitude": 45.49618557493205,
        "longitude": 12.253101244568825,
    },
    Object {
        "latitude": 45.49635266968306,
        "longitude": 12.252548038959503,
    },
    Object {
        "latitude": 45.496856301073855,
        "longitude": 12.25320216268301,
    },
    Object {
        "latitude": 45.496716939221876,
        "longitude": 12.25351095199585,
    },
],]

我认为这个 Double 数组是错误的,所以这就是我无法渲染多边形的原因。 谁能帮帮我?

【问题讨论】:

    标签: javascript reactjs react-native maps react-native-maps


    【解决方案1】:

    用坐标中的这行代码修复..

    <MapView.Polygon .. coordinates={poligonofinale[0]}/>

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-24
      • 2012-01-26
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      相关资源
      最近更新 更多