2gis/react-native-maps-old

Name: react-native-maps-old

Owner: 2GIS

Description: React Native Mapview component for iOS + Android

Created: 2016-08-11 05:17:51.0

Updated: 2017-11-03 20:58:44.0

Pushed: 2018-05-18 11:08:29.0

Homepage: null

Size: 796

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

react-native-maps

React Native Map components for iOS + Android

Installation

See Installation Instructions.

Compatibility

Due to the rapid changes being made in the React Native ecosystem, we are not officially going to support this module on anything but the latest version of React Native. With that said, we will do our best to stay compatible with older versions as much that is practical, and the peer dependency of this requirement is set to "react-native": "*" explicitly for this reason. If you are using an older version of React Native with this module though, some features may be buggy.

Note about React requires

Since react-native 0.25.0, React should be required from node_modules. React Native versions from 0.18 should be working out of the box, for lower versions you should add react as a dependency in your package.json.

General Usage
rt MapView from 'react-native-maps';

or

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.

Rendering a Map with an initial region
MapView
apView
initialRegion={{
  latitude: 37.78825,
  longitude: -122.4324,
  latitudeDelta: 0.0922,
  longitudeDelta: 0.0421,
}}

Using a MapView while controlling the region as state
nitialState() {
turn {
region: {
  latitude: 37.78825,
  longitude: -122.4324,
  latitudeDelta: 0.0922,
  longitudeDelta: 0.0421,
},



gionChange(region) {
is.setState({ region });


er() {
turn (
<MapView
  region={this.state.region}
  onRegionChange={this.onRegionChange}
/>


Rendering a list of markers on a map
View
gion={this.state.region}
RegionChange={this.onRegionChange}

his.state.markers.map(marker => (
<MapView.Marker
  coordinate={marker.latlng}
  title={marker.title}
  description={marker.description}
/>
}
pView>
Rendering a Marker with a custom view
View.Marker coordinate={marker.latlng}>
yCustomMarkerView {...marker} />
pView.Marker>
Rendering a Marker with a custom image
View.Marker
ordinate={marker.latlng}
age={require('../assets/pin.png')}

Rendering a custom Marker with a custom Callout
View.Marker coordinate={marker.latlng}>
yCustomMarkerView {...marker} />
apView.Callout>
<MyCustomCalloutView {...marker} />
MapView.Callout>
pView.Marker>
Draggable Markers
View initialRegion={...}>
apView.Marker draggable
coordinate={this.state.x}
onDragEnd={(e) => this.setState({ x: e.nativeEvent.coordinate })}

pView>
Examples
MapView Events

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.

Tracking Region / Location

Programmatically Changing Region

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.

Arbitrary React Views as Markers

Using the MapView with the Animated API

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.

Markers' coordinates can also be animated, as shown in this example:

Polygon Creator

Other Overlays

So far, <Circle />, <Polygon />, and <Polyline /> are available to pass in as children to the <MapView /> component.

Default Markers

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.

Custom Callouts

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.

Image-based Markers

Markers can be customized by just using images, and specified using the image prop.

Draggable Markers

Markers are draggable, and emit continuous drag events to update other UI during drags.

Component API

<MapView /> Component API

<MapView.Marker /> Component API

<MapView.Callout /> Component API

<MapView.Polygon /> Component API

<MapView.Polyline /> Component API

<MapView.Circle /> Component API

Using with the Animated API

The API of this Map has been built with the intention of it being able to utilize the Animated API.

In order to get this to work, you will need to modify the AnimatedImplementation.js file in the source of react-native with this one.

Ideally this will be possible in the near future without this modification.

Animated Region

The MapView can accept an Animated.Region value as its region prop. This allows you to utilize the Animated API to control the map's center and zoom.

nitialState() {
turn {
region: new Animated.Region({
  latitude: LATITUDE,
  longitude: LONGITUDE,
  latitudeDelta: LATITUDE_DELTA,
  longitudeDelta: LONGITUDE_DELTA,
}),



gionChange(region) {
is.state.region.setValue(region);


er() {
turn (
<MapView.Animated
  region={this.state.region}
  onRegionChange={this.onRegionChange}
/>


Animated Marker Position

Markers can also accept an Animated.Region value as a coordinate.

nitialState() {
turn {
coordinate: new Animated.Region({
  latitude: LATITUDE,
  longitude: LONGITUDE,
}),



er() {
turn (
<MapView initialRegion={...}>
  <MapView.Marker.Animated coordinate={this.state.coordinate} />
</MapView>


Take Snapshot of map

currently only for ios, android implementation WIP

nitialState() {
turn {
coordinate: {
  latitude: LATITUDE,
  longitude: LONGITUDE,
},



Snapshot () {
 arguments to 'takeSnapshot' are width, height, coordinates and callback
is.refs.map.takeSnapshot(300, 300, this.state.coordinate, (err, snapshot) => {
// snapshot contains image 'uri' - full path to image and 'data' - base64 encoded image
this.setState({ mapSnapshot: snapshot })



er() {
turn (
<View>
  <MapView initialRegion={...} ref="map">
    <MapView.Marker coordinate={this.state.coordinate} />
  </MapView>
  <Image source={{ uri: this.state.mapSnapshot.uri }} />
  <TouchableOpacity onPress={this.takeSnapshot}>
    Take Snapshot
  </TouchableOpacity>
</View>


Zoom to Specified Markers

Pass an array of marker identifiers to have the map re-focus.

Troubleshooting
My map is blank
t styles = StyleSheet.create({
p: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,


sx
View
yle={styles.map}
 other props

Inputs don't focus

Bad:

w>
extInput/>
apView/>
ew>

Good:

w>
apView/>
extInput/>
ew>
License
 Copyright (c) 2015 Leland Richardson

 Licensed under the The MIT License (MIT) (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

    https://raw.githubusercontent.com/lelandrichardson/react-native-maps/master/LICENSE

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.