Props
View props...
onAnnotationPress function
Deprecated. Use annotation onFocus and onBlur instead.
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 display it on the map. Default value is false
.
NOTE: on iOS, you need to add the NSLocationWhenInUseUsageDescription
key in Info.plist to enable geolocation, otherwise it will 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
.
androidactive bool
iosannotations [{latitude: number, longitude: number, animateDrop: bool, draggable: bool, onDragStateChange: function, onFocus: function, onBlur: function, title: string, subtitle: string, leftCalloutView: element, rightCalloutView: element, detailCalloutView: element, tintColor: [object Object], image: Image.propTypes.source, view: element, id: string, hasLeftCallout: deprecatedPropType( React.PropTypes.bool, 'Use `leftCalloutView` instead.' ), hasRightCallout: deprecatedPropType( React.PropTypes.bool, 'Use `rightCalloutView` instead.' ), onLeftCalloutPress: deprecatedPropType( React.PropTypes.func, 'Use `leftCalloutView` instead.' ), onRightCalloutPress: deprecatedPropType( React.PropTypes.func, 'Use `rightCalloutView` instead.' )}]
Map annotations with title/subtitle.
iosfollowUserLocation bool
If true
the map will follow the user's location whenever it changes. Note that this has no effect unless showsUserLocation
is enabled. Default value is true
.
ioslegalLabelInsets {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.
iosmapType 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 overlaid
iosmaxDelta number
Maximum size of area that can be displayed.
iosminDelta number
Minimum size of area that can be displayed.
iosoverlays [{coordinates: [object Object], lineWidth: number, strokeColor: [object Object], fillColor: [object Object], id: string}]
Map overlays
iosshowsCompass bool
If false
compass won't be displayed on the map. Default value is true
.
iosshowsPointsOfInterest bool
If false
points of interest won't be displayed on the map. Default value is true
.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | 'use strict' ; var React = require( 'react' ); var ReactNative = require( 'react-native' ); var { PropTypes } = React; var { Image, MapView, StyleSheet, Text, TextInput, TouchableOpacity, View, } = ReactNative; var regionText = { latitude: '0' , longitude: '0' , latitudeDelta: '0' , longitudeDelta: '0' , }; var MapRegionInput = React.createClass({ propTypes: { region: PropTypes.shape({ latitude: PropTypes.number.isRequired, longitude: PropTypes.number.isRequired, latitudeDelta: PropTypes.number, longitudeDelta: PropTypes.number, }), onChange: PropTypes.func.isRequired, }, getInitialState() { return { region: { latitude: 0, longitude: 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 == null ? '' : String(region.latitudeDelta) } style={styles.textInput} onChange={ this ._onChangeLatitudeDelta} selectTextOnFocus={ true } /> </View> <View style={styles.row}> <Text> { 'Longitude delta' } </Text> <TextInput value={ region.longitudeDelta == null ? '' : String(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({ region: { 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 { isFirstLoad: true , mapRegion: undefined, mapRegionInput: undefined, annotations: [], }; }, render() { return ( <View> <MapView style={styles.map} onRegionChange={ this ._onRegionChange} onRegionChangeComplete={ this ._onRegionChangeComplete} region={ this .state.mapRegion} annotations={ this .state.annotations} /> <MapRegionInput onChange={ this ._onRegionInputChanged} region={ this .state.mapRegionInput} /> </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 AnnotationExample = React.createClass({ getInitialState() { return { isFirstLoad: true , annotations: [], mapRegion: undefined, }; }, render() { if ( this .state.isFirstLoad) { var onRegionChangeComplete = (region) => { this .setState({ isFirstLoad: false , annotations: [{ longitude: region.longitude, latitude: region.latitude, ... this .props.annotation, }], }); }; } return ( <MapView style={styles.map} onRegionChangeComplete={onRegionChangeComplete} region={ this .state.mapRegion} annotations={ this .state.annotations} /> ); }, }); 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() { return <MapViewExample />; } }, { title: 'showsUserLocation + followUserLocation' , render() { return ( <MapView style={styles.map} showsUserLocation={ true } followUserLocation={ true } /> ); } }, { title: 'Callout example' , render() { return <AnnotationExample style={styles.map} annotation={{ title: 'More Info...' , rightCalloutView: ( <TouchableOpacity onPress={() => { alert( 'You Are Here' ); }}> <Image style={{width:30, height:30}} source={require( './uie_thumb_selected.png' )} /> </TouchableOpacity> ), }}/>; } }, { title: 'Annotation focus example' , render() { return <AnnotationExample style={styles.map} annotation={{ title: 'More Info...' , onFocus: () => { alert( 'Annotation gets focus' ); }, onBlur: () => { alert( 'Annotation lost focus' ); } }}/>; } }, { title: 'Draggable pin' , render() { return <AnnotationExample style={styles.map} annotation={{ draggable: true , onDragStateChange: (event) => { console.log( 'Drag state: ' + event.state); }, }}/>; } }, { title: 'Custom pin color' , render() { return <AnnotationExample style={styles.map} annotation={{ title: 'You Are Purple' , tintColor: MapView.PinColors.PURPLE, }}/>; } }, { title: 'Custom pin image' , render() { return <AnnotationExample style={styles.map} annotation={{ title: 'Thumbs Up!' , image: require( 'image!uie_thumb_big' ), }}/>; } }, { title: 'Custom pin view' , render() { return <AnnotationExample style={styles.map} annotation={{ title: 'Thumbs Up!' , view: <View style={{ alignItems: 'center' , }}> <Text style={{fontWeight: 'bold' , color: '#f007' }}> Thumbs Up! </Text> <Image style={{width: 90, height: 65, resizeMode: 'cover' }} source={require( 'image!uie_thumb_big' )} /> </View>, }}/>; } }, { title: 'Custom overlay' , render() { return <MapView style={styles.map} region={{ latitude: 39.06, longitude: -95.22, }} overlays={[{ coordinates:[ {latitude: 32.47, longitude: -107.85}, {latitude: 45.13, longitude: -94.48}, {latitude: 39.27, longitude: -83.25}, {latitude: 32.47, longitude: -107.85}, ], strokeColor: '#f007' , lineWidth: 3, }]} />; } }, ]; |