Adding a marker in React Native MapsStart by importing Marker from react-native-maps . import { Marker } from "react-native-maps"; Next, render the <Marker /> component as a child of <MapView /> . Pass the coordinate for the marker in the coordinate prop.
Copy your API key into app. In your code, import { PROVIDER_GOOGLE } from react-native-maps and add the property provider=PROVIDER_GOOGLE to your <MapView> . This property works on both iOS and Android. Rebuild the app binary. An easy way to test that the configuration was successful is to do a simulator build.
Thank you @naoufal. Finally I am able to display markers on map for react native IOS.
<View style={styles.container}> <MapView style={styles.map} initialRegion={{ latitude: 37.78825, longitude: -122.4324, latitudeDelta: 0.0, longitudeDelta: 0.0, }} > <MapView.Marker coordinate={{latitude: 37.78825, longitude: -122.4324}} title={"title"} description={"description"} /> </MapView> </View>
For map and container styles, I have used following styles:
var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, map: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, } });
I have referred following link: React native IOS- Display Markers on map
You can set markers using the annotations
prop.
For example:
var markers = [ { latitude: 45.65, longitude: -78.90, title: 'Foo Place', subtitle: '1234 Foo Drive' } ]; <MapView region={...} annotations={markers} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With