我想在 react native 中使用纬度和经度在谷歌地图中绘制多边形



如何使用 React native 在 Google 地图中绘制多边形。我有一个纬度和经度的数组列表,我想使用纬度和经度在谷歌地图中绘制多边形。

这就是答案

<MapView>
<Polygon
coordinates={[
{ latitude: 37.8025259, longitude: -122.4351431 },
{ latitude: 37.7896386, longitude: -122.421646 },
{ latitude: 37.7665248, longitude: -122.4161628 },
{ latitude: 37.7734153, longitude: -122.4577787 },
{ latitude: 37.7948605, longitude: -122.4596065 },
{ latitude: 37.8025259, longitude: -122.4351431 }
]}
strokeColor="#000" // fallback for when `strokeColors` is not supported by the map-provider
strokeColors={[
'#7F0000',
'#00000000', // no color, creates a "long" gradient between the previous and next coordinate
'#B24112',
'#E5845C',
'#238C23',
'#7F0000'
]}
strokeWidth={6}
/>
</MapView>

请检查所述包的文档,多边形组件接受坐标数组来绘制它。

应该在这些线周围,其中您的状态是一个坐标数组。

<Polygon coordinates={this.state.coordinates}/>

https://github.com/react-community/react-native-maps/blob/master/docs/polygon.md

最新更新