Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a marker in MapView of React Native

Tags:

  • I want to set a marker on MapView in React Native, but I can't find any information through official documents of MapView.
  • If it is not allowed in that way, how can I use existed react module such as react-googlemaps in React Native?
like image 240
ivan wang Avatar asked Apr 02 '15 12:04

ivan wang


People also ask

How do you set a marker in react-native?

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.

How do I use MapView in react-native?

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.


2 Answers

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

like image 160
BK19 Avatar answered Oct 09 '22 09:10

BK19


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} /> 
like image 23
naoufal Avatar answered Oct 09 '22 09:10

naoufal