首页 > 解决方案 > 我想在谷歌地图中使用纬度和经度在反应原生中绘制多边形

问题描述

如何使用本机反应在谷歌地图中绘制多边形。我有一个纬度和经度的数组列表我想使用纬度和经度在谷歌地图中绘制多边形。

标签: react-nativereact-native-androidreact-native-maps

解决方案


这是答案

<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>

推荐阅读