Search code examples
react-nativereact-native-maps

How can I limit react-native-maps?


I use react-native-map. I want to limit mapView coordinates because I need to see just one city. How can I do that?

<MapView
    style={styles.map}
    minZoomLevel={12}
    maxZoomLevel={15}
    initialRegion={{
        latitude: this.state.lat,
        longitude: this.state.long,
        latitudeDelta: this.state.latdelta,
            longitudeDelta: this.state.longdelta,
    }}
    provider={ PROVIDER_GOOGLE}
        onPress={(e) => this.onMapPress(e)}
    >
    {this.state.markers.map(marker => (
    <Marker
        key={marker.key}
        coordinate={marker.coordinate}
    />
))}


Solution

  • You cannot set a limit on Map view. But you can draw a Polygon with your city lat lng. Checkout polygon attribute from here.