Last active
February 17, 2020 13:18
-
-
Save abegehr/39d7ef424995d871baf34dcd38f83c08 to your computer and use it in GitHub Desktop.
simple App.js with react-native-map-clustering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { StyleSheet, View } from "react-native"; | |
import MapView from "react-native-map-clustering"; | |
import { Marker } from "react-native-maps"; | |
const initialRegion = { | |
latitude: 37.72825, | |
longitude: -122.4324, | |
latitudeDelta: 0.25, | |
longitudeDelta: 0.15 | |
}; | |
function renderRandomMarkers(n) { | |
const { latitude, longitude, latitudeDelta, longitudeDelta } = initialRegion; | |
return new Array(n).fill().map((x, i) => ( | |
<Marker | |
key={i} | |
coordinate={{ | |
latitude: latitude + (Math.random() - 0.5) * latitudeDelta, | |
longitude: longitude + (Math.random() - 0.5) * longitudeDelta | |
}} | |
/> | |
)); | |
} | |
export default function App() { | |
return ( | |
<View style={styles.container}> | |
<MapView style={styles.map} initialRegion={initialRegion}> | |
{renderRandomMarkers(144)} | |
</MapView> | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1 | |
}, | |
map: { | |
width: "100%", | |
height: "100%" | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment