React Native Map components for iOS + Android
See Installation Instructions.
import MapView from 'react-native-maps';
or
var MapView = require('react-native-maps');
This MapView component is built so that features on the map (such as Markers, Polygons, etc.) are specified as children of the MapView itself. This provides an intuitive and react-like API for declaratively controlling features on the map.
<MapView
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
getInitialState() {
return {
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
};
}
onRegionChange(region) {
this.setState({ region });
}
render() {
return (
<MapView
region={this.state.region}
onRegionChange={this.onRegionChange}
/>
);
}
<MapView
region={this.state.region}
onRegionChange={this.onRegionChange}
>
{this.state.markers.map(marker => (
<MapView.Marker
coordinate={marker.latlng}
title={marker.title}
description={marker.description}
/>
))}
</MapView>
<MapView.Marker coordinate={marker.latlng}>
<MyCustomMarkerView {...marker} />
</MapView.Marker>
<MapView.Marker
coordinate={marker.latlng}
image={require('../assets/pin.png')}
/>
<MapView.Marker coordinate={marker.latlng}>
<MyCustomMarkerView {...marker} />
<MapView.Callout>
<MyCustomCalloutView {...marker} />
</MapView.Callout>
</MapView.Marker>
The <MapView />
component and its child components have several events that you can subscribe to.
This example displays some of them in a log as a demonstration.
One can change the mapview's position using refs and component methods, or by passing in an updated
region
prop. The component methods will allow one to animate to a given position like the native
API could.
The <MapView />
component can be made to work with the Animated API, having the entire region
prop
be declared as an animated value. This allows one to animate the zoom and position of the MapView along
with other gestures, giving a nice feel.
Further, Marker views can use the animated API to enhance the effect.
Issue: Since android needs to render its marker views as a bitmap, the animations APIs may not be compatible with the Marker views. Not sure if this can be worked around yet or not.
So far, <Circle />
, <Polygon />
, and <Polyline />
are available to pass in as children to the
<MapView />
component.
Default markers will be rendered unless a custom marker is specified. One can optionally adjust the
color of the default marker by using the pinColor
prop.
Callouts to markers can be completely arbitrary react views, similar to markers. As a result, they can be interacted with like any other view.
Additionally, you can fall back to the standard behavior of just having a title/description through
the <Marker />
's title
and description
props.
Custom callout views can be the entire tooltip bubble, or just the content inside of the system default bubble.
Markers can be customized by just using images, and specified using the image
prop.
<MapView.Marker />
Component API
<MapView.Callout />
Component API
<MapView.Polygon />
Component API