Aditya
Aditya

Reputation: 53

I want to draw polygon inside google maps using latitude and longitude in react native

how to draw polygon in google maps using react native .I have a array list of latitude and longitude I want to draw polygon inside google maps using latitude and longitude .

Upvotes: 2

Views: 3826

Answers (2)

Aditya
Aditya

Reputation: 53

This is the Answer

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

Upvotes: 1

markymark
markymark

Reputation: 145

Please check the docs for said package, Polygon component accepts an Array of coordinates to draw it.

Should be around these lines where your state is an array of coordinates.

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

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

Upvotes: 0

Related Questions