MapView

Edit on GitHubProps #

annotations [{latitude: number, longitude: number, animateDrop: bool, title: string, subtitle: string, hasLeftCallout: bool, hasRightCallout: bool, onLeftCalloutPress: function, onRightCalloutPress: function, id: string}] #

Map annotations with title/subtitle.

legalLabelInsets {top: number, left: number, bottom: number, right: number} #

Insets for the map's legal label, originally at bottom left of the map. See EdgeInsetsPropType.js for more information.

mapType enum('standard', 'satellite', 'hybrid') #

The map type to be displayed.

  • standard: standard road map (default)
  • satellite: satellite view
  • hybrid: satellite view with roads and points of interest overlayed

maxDelta number #

Maximum size of area that can be displayed.

minDelta number #

Minimum size of area that can be displayed.

onAnnotationPress function #

Callback that is called once, when the user taps an annotation.

onRegionChange function #

Callback that is called continuously when the user is dragging the map.

onRegionChangeComplete function #

Callback that is called once, when the user is done moving the map.

pitchEnabled bool #

When this property is set to true and a valid camera is associated with the map, the camera’s pitch angle is used to tilt the plane of the map. When this property is set to false, the camera’s pitch angle is ignored and the map is always displayed as if the user is looking straight down onto it.

region {latitude: number, longitude: number, latitudeDelta: number, longitudeDelta: number} #

The region to be displayed by the map.

The region is defined by the center coordinates and the span of coordinates to display.

rotateEnabled bool #

When this property is set to true and a valid camera is associated with the map, the camera’s heading angle is used to rotate the plane of the map around its center point. When this property is set to false, the camera’s heading angle is ignored and the map is always oriented so that true north is situated at the top of the map view

scrollEnabled bool #

If false the user won't be able to change the map region being displayed. Default value is true.

showsUserLocation bool #

If true the app will ask for the user's location and focus on it. Default value is false.

NOTE: You need to add NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation, otherwise it is going to fail silently!

style View#style #

Used to style and layout the MapView. See StyleSheet.js and ViewStylePropTypes.js for more info.

zoomEnabled bool #

If false the user won't be able to pinch/zoom the map. Default value is true.

iosshowsPointsOfInterest bool #

If false points of interest won't be displayed on the map. Default value is true.

Edit on GitHubExamples #

'use strict'; var React = require('react-native'); var { MapView, StyleSheet, Text, TextInput, View, } = React; var regionText = { latitude: '0', longitude: '0', latitudeDelta: '0', longitudeDelta: '0', }; var MapRegionInput = React.createClass({ propTypes: { region: React.PropTypes.shape({ latitude: React.PropTypes.number.isRequired, longitude: React.PropTypes.number.isRequired, latitudeDelta: React.PropTypes.number.isRequired, longitudeDelta: React.PropTypes.number.isRequired, }), onChange: React.PropTypes.func.isRequired, }, getInitialState: function() { return { region: { latitude: 0, longitude: 0, latitudeDelta: 0, longitudeDelta: 0, } }; }, componentWillReceiveProps: function(nextProps) { this.setState({ region: nextProps.region || this.getInitialState().region }); }, render: function() { var region = this.state.region || this.getInitialState().region; return ( <View> <View style={styles.row}> <Text> {'Latitude'} </Text> <TextInput value={'' + region.latitude} style={styles.textInput} onChange={this._onChangeLatitude} selectTextOnFocus={true} /> </View> <View style={styles.row}> <Text> {'Longitude'} </Text> <TextInput value={'' + region.longitude} style={styles.textInput} onChange={this._onChangeLongitude} selectTextOnFocus={true} /> </View> <View style={styles.row}> <Text> {'Latitude delta'} </Text> <TextInput value={'' + region.latitudeDelta} style={styles.textInput} onChange={this._onChangeLatitudeDelta} selectTextOnFocus={true} /> </View> <View style={styles.row}> <Text> {'Longitude delta'} </Text> <TextInput value={'' + region.longitudeDelta} style={styles.textInput} onChange={this._onChangeLongitudeDelta} selectTextOnFocus={true} /> </View> <View style={styles.changeButton}> <Text onPress={this._change}> {'Change'} </Text> </View> </View> ); }, _onChangeLatitude: function(e) { regionText.latitude = e.nativeEvent.text; }, _onChangeLongitude: function(e) { regionText.longitude = e.nativeEvent.text; }, _onChangeLatitudeDelta: function(e) { regionText.latitudeDelta = e.nativeEvent.text; }, _onChangeLongitudeDelta: function(e) { regionText.longitudeDelta = e.nativeEvent.text; }, _change: function() { this.setState({ latitude: parseFloat(regionText.latitude), longitude: parseFloat(regionText.longitude), latitudeDelta: parseFloat(regionText.latitudeDelta), longitudeDelta: parseFloat(regionText.longitudeDelta), }); this.props.onChange(this.state.region); }, }); var MapViewExample = React.createClass({ getInitialState() { return { mapRegion: null, mapRegionInput: null, annotations: null, isFirstLoad: true, }; }, render() { return ( <View> <MapView style={styles.map} onRegionChange={this._onRegionChange} onRegionChangeComplete={this._onRegionChangeComplete} region={this.state.mapRegion || undefined} annotations={this.state.annotations || undefined} /> <MapRegionInput onChange={this._onRegionInputChanged} region={this.state.mapRegionInput || undefined} /> </View> ); }, _getAnnotations(region) { return [{ longitude: region.longitude, latitude: region.latitude, title: 'You Are Here', }]; }, _onRegionChange(region) { this.setState({ mapRegionInput: region, }); }, _onRegionChangeComplete(region) { if (this.state.isFirstLoad) { this.setState({ mapRegionInput: region, annotations: this._getAnnotations(region), isFirstLoad: false, }); } }, _onRegionInputChanged(region) { this.setState({ mapRegion: region, mapRegionInput: region, annotations: this._getAnnotations(region), }); }, }); var styles = StyleSheet.create({ map: { height: 150, margin: 10, borderWidth: 1, borderColor: '#000000', }, row: { flexDirection: 'row', justifyContent: 'space-between', }, textInput: { width: 150, height: 20, borderWidth: 0.5, borderColor: '#aaaaaa', fontSize: 13, padding: 4, }, changeButton: { alignSelf: 'center', marginTop: 5, padding: 3, borderWidth: 0.5, borderColor: '#777777', }, }); exports.displayName = (undefined: ?string); exports.title = '<MapView>'; exports.description = 'Base component to display maps'; exports.examples = [ { title: 'Map', render(): ReactElement { return <MapViewExample />; } }, { title: 'Map shows user location', render() { return <MapView style={styles.map} showsUserLocation={true} />; } } ];