Giter VIP home page Giter VIP logo

react-native-maps's Introduction

react-native-maps npm version

React Native Map components for iOS + Android

Contributing

This project is being maintained by a small group of people, and any help with issues and pull requests are always appreciated. If you are able and willing to contribute, please read the guidelines.

Installation

See Installation Instructions.

See Setup Instructions for the Included Example Project.

Compatibility

react-native-maps requires react-native >= 0.64.3.

Component API

<MapView /> Component API

<Marker /> Component API

<Callout /> Component API

<Polygon /> Component API

<Polyline /> Component API

<Circle /> Component API

<Overlay /> Component API

<Heatmap /> Component API

<Geojson /> Component API

General Usage

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.

Rendering a Map with an initial region

MapView

<MapView
  initialRegion={{
    latitude: 37.78825,
    longitude: -122.4324,
    latitudeDelta: 0.0922,
    longitudeDelta: 0.0421,
  }}
/>

Using a MapView while controlling the region as state

getInitialState() {
  return {
    region: {
      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}
    />
  );
}

Rendering a list of markers on a map

import {Marker} from 'react-native-maps';

<MapView region={this.state.region} onRegionChange={this.onRegionChange}>
  {this.state.markers.map((marker, index) => (
    <Marker
      key={index}
      coordinate={marker.latlng}
      title={marker.title}
      description={marker.description}
    />
  ))}
</MapView>;

Rendering a Marker with a custom image

  1. You need to generate an png image with various resolution (lets call them custom_pin) - for more information go to Android, iOS
  2. put all images in Android drawables and iOS assets dir
  3. Now you can use the following code:
<Marker
  coordinate={{latitude: latitude, longitude: longitude}}
  image={{uri: 'custom_pin'}}
/>

Note: You can also pass the image binary data like image={require('custom_pin.png')}, but this will not scale good with the different screen sizes.

Rendering a Marker with a custom view

Note: This has performance implications, if you wish for a simpler solution go with a custom image (save your self the head ache)

<Marker coordinate={{latitude: latitude, longitude: longitude}}>
  <MyCustomMarkerView {...marker} />
</Marker>

Rendering a custom Marker with a custom Callout

import {Callout} from 'react-native-maps';

<Marker coordinate={marker.latlng}>
  <MyCustomMarkerView {...marker} />
  <Callout>
    <MyCustomCalloutView {...marker} />
  </Callout>
</Marker>;

Draggable Markers

<MapView initialRegion={...}>
  <Marker draggable
    coordinate={this.state.x}
    onDragEnd={(e) => this.setState({ x: e.nativeEvent.coordinate })}
  />
</MapView>

Using a custom Tile Overlay

Tile Overlay using tile server

import {UrlTile} from 'react-native-maps';

<MapView region={this.state.region} onRegionChange={this.onRegionChange}>
  <UrlTile
    /**
     * The url template of the tile server. The patterns {x} {y} {z} will be replaced at runtime
     * For example, http://c.tile.openstreetmap.org/{z}/{x}/{y}.png
     */
    urlTemplate={this.state.urlTemplate}
    /**
     * The maximum zoom level for this tile overlay. Corresponds to the maximumZ setting in
     * MKTileOverlay. iOS only.
     */
    maximumZ={19}
    /**
     * flipY allows tiles with inverted y coordinates (origin at bottom left of map)
     * to be used. Its default value is false.
     */
    flipY={false}
  />
</MapView>;

For Android: add the following line in your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

For IOS: configure App Transport Security in your app

Tile Overlay using local tiles

Tiles can be stored locally within device using xyz tiling scheme and displayed as tile overlay as well. This is usefull especially for offline map usage when tiles are available for selected map region within device storage.

import {LocalTile} from 'react-native-maps';

<MapView region={this.state.region} onRegionChange={this.onRegionChange}>
  <LocalTile
    /**
     * The path template of the locally stored tiles. The patterns {x} {y} {z} will be replaced at runtime
     * For example, /storage/emulated/0/mytiles/{z}/{x}/{y}.png
     */
    pathTemplate={this.state.pathTemplate}
    /**
     * The size of provided local tiles (usually 256 or 512).
     */
    tileSize={256}
  />
</MapView>;

For Android: LocalTile is still just overlay over original map tiles. It means that if device is online, underlying tiles will be still downloaded. If original tiles download/display is not desirable set mapType to 'none'. For example:

<MapView
  mapType={Platform.OS == "android" ? "none" : "standard"}
>

See OSM Wiki for how to download tiles for offline usage.

Overlaying other components on the map

Place components that you wish to overlay MapView underneath the MapView closing tag. Absolutely position these elements.

render() {
  return (
    <MapView
      region={this.state.region}
    />
    <OverlayComponent
      style={{position: "absolute", bottom: 50}}
    />
  );
}

Customizing the map style

Create the json object, or download a generated one from the google style generator.

// The generated json object
mapStyle = [ ... ]

render() {
  return (
    <MapView
      region={this.state.region}
      onRegionChange={this.onRegionChange}
      customMapStyle={mapStyle}
    />
  );
}

For iOS, in addition to providing the mapStyle you will need to do the following

import MapView, { PROVIDER_GOOGLE } from 'react-native-maps'

// ...

<MapView
  provider={PROVIDER_GOOGLE}
  customMapStyle={MapStyle}
>

Then add the AirGoogleMaps directory:

https://github.com/react-native-maps/react-native-maps/blob/1e71a21f39e7b88554852951f773c731c94680c9/docs/installation.md#ios

An unofficial step-by-step guide is also available at https://gist.github.com/heron2014/e60fa003e9b117ce80d56bb1d5bfe9e0

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.

Changing the style of the map

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.

Gradient Polylines (iOS MapKit only)

Gradient polylines can be created using the strokeColors prop of the <Polyline> 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.

To handle press on specific subview of callout use <CalloutSubview /> with onPress. See Callouts.js example.

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.

Lite Mode ( Android )

Enable lite mode on Android with liteMode prop. Ideal when having multiple maps in a View or ScrollView.

On Poi Click (Google Maps Only)

Poi are clickable, you can catch the event to get its information (usually to get the full detail from Google Place using the placeId).

Animated Region

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

import MapView, { AnimatedRegion, Animated } from 'react-native-maps';

getInitialState() {
  return {
    region: new AnimatedRegion({
      latitude: LATITUDE,
      longitude: LONGITUDE,
      latitudeDelta: LATITUDE_DELTA,
      longitudeDelta: LONGITUDE_DELTA,
    }),
  };
}

onRegionChange(region) {
  this.state.region.setValue(region);
}

render() {
  return (
    <Animated
      region={this.state.region}
      onRegionChange={this.onRegionChange}
    />
  );
}

Animated Marker Position

Markers can also accept an AnimatedRegion value as a coordinate.

import Mapview, { AnimatedRegion, MarkerAnimated } from 'react-native-maps';

getInitialState() {
  return {
    coordinate: new AnimatedRegion({
      latitude: LATITUDE,
      longitude: LONGITUDE,
    }),
  };
}

componentWillReceiveProps(nextProps) {
  const duration = 500

  if (this.props.coordinate !== nextProps.coordinate) {
    if (Platform.OS === 'android') {
      if (this.marker) {
        this.marker.animateMarkerToCoordinate(
          nextProps.coordinate,
          duration
        );
      }
    } else {
      this.state.coordinate.timing({
        ...nextProps.coordinate,
        useNativeDriver: true, // defaults to false if not passed explicitly
        duration
      }).start();
    }
  }
}

render() {
  return (
    <MapView initialRegion={...}>
      <MarkerAnimated
        ref={marker => { this.marker = marker }}
        coordinate={this.state.coordinate}
      />
    </MapView>
  );
}

Take Snapshot of map

import MapView, { Marker } from 'react-native-maps';

getInitialState() {
  return {
    coordinate: {
      latitude: LATITUDE,
      longitude: LONGITUDE,
    },
  };
}

takeSnapshot () {
  // 'takeSnapshot' takes a config object with the
  // following options
  const snapshot = this.map.takeSnapshot({
    width: 300,      // optional, when omitted the view-width is used
    height: 300,     // optional, when omitted the view-height is used
    region: {..},    // iOS only, optional region to render
    format: 'png',   // image formats: 'png', 'jpg' (default: 'png')
    quality: 0.8,    // image quality: 0..1 (only relevant for jpg, default: 1)
    result: 'file'   // result types: 'file', 'base64' (default: 'file')
  });
  snapshot.then((uri) => {
    this.setState({ mapSnapshot: uri });
  });
}

render() {
  return (
    <View>
      <MapView initialRegion={...} ref={map => { this.map = map }}>
        <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.

Zoom to Specified Coordinates

Pass an array of coordinates to focus a map region on said coordinates.

Troubleshooting

My map is blank

  • Make sure that you have properly installed react-native-maps.
  • Check in the logs if there is more informations about the issue.
  • Try setting the style of the MapView to an absolute position with top, left, right and bottom values set.
  • Make sure you have enabled Google Maps API in Google developer console
const styles = StyleSheet.create({
  map: {
    ...StyleSheet.absoluteFillObject,
  },
});
<MapView
  style={styles.map}
  // other props
/>

Inputs don't focus

  • When inputs don't focus or elements don't respond to tap, look at the order of the view hierarchy, sometimes the issue could be due to ordering of rendered components, prefer putting MapView as the first component.

Bad:

<View>
  <TextInput />
  <MapView />
</View>

Good:

<View>
  <MapView />
  <TextInput />
</View>

Children Components Not Re-Rendering

Components that aren't declared by this library (Ex: Markers, Polyline) must not be children of the MapView component due to MapView's unique rendering methodology. Have your custom components / views outside the MapView component and position absolute to ensure they only re-render as needed. Example: Bad:

<View style={StyleSheet.absoluteFillObject}>
  <MapView style={StyleSheet.absoluteFillObject}>
    <View style={{position: 'absolute', top: 100, left: 50}} />
  </MapView>
</View>

Good:

<View style={StyleSheet.absoluteFillObject}>
  <MapView style={StyleSheet.absoluteFillObject} />
  <View style={{position: 'absolute', top: 100, left: 50}} />
</View>

Source: #1901

Crashing with EXC_BAD_ACCESS on iOS when switching apps

<MapView> using Apple Maps in mapType: "standard" will sometimes crash when you background the app or switch into another app. This is only an issue in XCode using Metal API Validation, and won't happen in production. To eliminate this problem even while debugging in XCode, go to Edit Scheme... -> Run (Debug) -> Diagnostics and uncheck Metal -> API Validation. (h/t @Simon-TechForm).

Source: #3957 (comment)

onRegionChangeComplete() callback is called infinitely

If changing the state in onRegionChangeComplete is called infinitely, add a condition to limit these calls to occur only when the region change was done as a result of a user's action.

onRegionChangeComplete={ (region, gesture) => {
	// This fix only works on Google Maps because isGesture is NOT available on Apple Maps
	if (!gesture.isGesture) {
    return;
  }

  // You can use
  dispatch({ type: "map_region", payload: { mapRegion: region }}); // if using useReducer
	// setMapRegionState(region); // if using useState
}}

Source: #846 (comment)

License

 Copyright (c) 2017 Airbnb

 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/airbnb/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.

react-native-maps's People

Contributors

alexander-veligurov avatar alvelig avatar bhishaksanyal avatar brentvatne avatar chrisknepper avatar christopherdro avatar danielgindi avatar dependabot[bot] avatar felipecsl avatar friederbluemle avatar gilbox avatar gpeal avatar hedgepigdaniel avatar ijzerenhein avatar jan-kozinski avatar jrichardlai avatar lelandrichardson avatar mlanter avatar monholm avatar naoufal avatar ochanje210 avatar paitoanderson avatar rborn avatar salah-ghanim avatar satori-ytolstoguzov avatar semantic-release-bot avatar skellock avatar terribleben avatar wrathchaos avatar zavadpe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-maps's Issues

Android onRegionChange Issue

I'm having an issue with Android (doesn't happen on iOS). Whenever I add onRegionChange to the MapView and set the state's region to the region passed (like the DisplayLatLng.js example), the view maps gets "laggy" or "grabby" like something is fighting the display region to be displayed. That's not very descriptive, so here's a video which hopefully shows what I'm talking about:

https://www.youtube.com/watch?v=IAXM2LQFmIw

Thanks again for making this!

Support react-native < 0.17

I've seen similar issues, but nothing have helped.

I'm receiving this error while debugging in chrome:

Warning: Native component for "AIRMapMarker" does not exist
Warning: Native component for "AIRMapPolyline" does not exist
Warning: Native component for "AIRMapPolygon" does not exist
Warning: Native component for "AIRMapCircle" does not exist
Warning: Native component for "AIRMapCallout" does not exist
Warning: Native component for "AIRMap" does not exist

Both ios and android have blank screen.
May it be because i'm using react-native 0.15?
I've checked out release notes and didn't found significant updates, which may make impossible to use this package without updating react-native

<MapView.Circle /> does not update its position when changing its center

I'm trying to put a circle in the center of my map. I have the following :

<MapView.Circle
    center={{latitude: this.state.region.latitude, longitude: this.state.region.longitude}}
    radius=1000
    fillColor="rgba(0, 0, 0, 0.2)"
    strokeColor="rgba(0, 0, 0, 0.2)"/>

but the circle doesn't change when I change region while my MapView has a onRegionChange method that sets the new region

onRegionChange = (region) => {
    this.setState({region: region});
}

Android: View marker does not update when only opacity style changes

On a re-render, if the view marker only has an opacity style change, the marker does not reflect the new opacity. However, if the marker also has a key or text change, the marker does reflect the new opacity. Example below. Note that iOS works as expected. Thanks!

Versions:

"react-native": "^0.19.0",
"react-native-maps": "^0.3.0",

Google Nexus 4, 5.1.0 emulator

Example:

var React = require('react-native');
var {
  StyleSheet,
  View,
  Text,
  Dimensions,
  TouchableOpacity,
  } = React;

var MapView = require('react-native-maps');
var PriceMarker = require('./PriceMarker');

var { width, height } = Dimensions.get('window');

const ASPECT_RATIO = width / height;
const LATITUDE = 37.78825;
const LONGITUDE = -122.4324;
const LATITUDE_DELTA = 0.0922;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;

var BugPlay = React.createClass({
  getInitialState() {
    return {
      region: {
        latitude: LATITUDE,
        longitude: LONGITUDE,
        latitudeDelta: LATITUDE_DELTA,
        longitudeDelta: LONGITUDE_DELTA,
      },
      coordinate: {
        latitude: LATITUDE,
        longitude: LONGITUDE,
      },
      coordinate2: {
        latitude: LATITUDE + 0.01,
        longitude: LONGITUDE,
      },
      coordinate3: {
        latitude: LATITUDE + 0.02,
        longitude: LONGITUDE,
      },
      amount: 99,
      opacity: 0.5
    };
  },

  changeOpacity() {
    this.setState({opacity: Math.random()});
  },

  render() {
    return (
      <View style={styles.container} opacity={this.state.opacity}>
        <MapView
          style={styles.map}
          initialRegion={this.state.region}
        >
          <MapView.Marker coordinate={this.state.coordinate}>
            <View style={{opacity: this.state.opacity, backgroundColor: 'red'}}>
              <Text style={styles.dollar}>Foo</Text>
            </View>
          </MapView.Marker>
          <MapView.Marker coordinate={this.state.coordinate2}>
            <View style={{opacity: this.state.opacity, backgroundColor: 'red'}}>
              <Text style={styles.dollar} key={this.state.opacity}>Key Change</Text>
            </View>
          </MapView.Marker>
          <MapView.Marker coordinate={this.state.coordinate3}>
            <View style={{opacity: this.state.opacity, backgroundColor: 'red'}}>
              <Text style={styles.dollar}>Text Change {this.state.opacity}</Text>
            </View>
          </MapView.Marker>
        </MapView>
        <View style={styles.buttonContainer}>
          <TouchableOpacity onPress={this.changeOpacity} style={[styles.bubble, styles.button]}>
            <Text style={{ fontSize: 20, fontWeight: 'bold' }}>change opacity</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  },
});

var styles = StyleSheet.create({
  container: {
    position: 'absolute',
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
  map: {
    position: 'absolute',
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
  },
  bubble: {
    backgroundColor: 'rgba(255,255,255,0.7)',
    paddingHorizontal: 18,
    paddingVertical: 12,
    borderRadius: 20,
  },
  latlng: {
    width: 200,
    alignItems: 'stretch',
  },
  button: {
    width: 200,
    paddingHorizontal: 12,
    alignItems: 'center',
    marginHorizontal: 10,
  },
  buttonContainer: {
    flexDirection: 'row',
    marginVertical: 20,
    backgroundColor: 'transparent',
  },
});

module.exports = BugPlay;

Plans on creating library

Hey there,

First off, great work! I haven't had a chance to dig too much but overall the looks very thorough and well coded. I was just curious of what your plans are with this project?

I've been working with the mapbox library for the last 2 weeks for a project but has started to become a hassle so am looking for an alternative map library to use for our companies project.

I, along would other devs would also be happy to help to get this package as a proper RN library.

Thanks

Constant White-Screen

Hey there. I tried this module on Android RN .17 but unfortunately the only thing i see is a white-screen. Any ideas?

 var MapTest = React.createClass({
        getInitialState() {
            return {
                latitude: 37.78825,
                longitude: -122.4324,
                latitudeDelta: 0.0922,
                longitudeDelta: 0.0421
            };
        },
        onRegionChange(region) {
            this.setState({region});
        },
        render: function () {
            return (
                <View style={{flex: 1, padding: 10}}>
                    <Text style={{alignSelf: 'center'}}>TEST</Text>
                    <View style={{flex: 1, borderWidth: 1}}>
                        <MapView
                            region={this.state.region}
                            onRegionChange={this.onRegionChange}
                        />
                    </View>
                </View>
            );
        }
    });

Load markers, old ios versions.

Hi All,

I'm wondering if there is some reason for the markers are not being loaded on the map for old ios versions, I'm testing on 7.1.2 iPhone4 the map loads ok, but somehow not the markers. I have antoher iPhone5s with the latest version and everything load fine.

Thanks.

showCallout method usage

I'm trying programmatically show the callout of a particular marker by using the showCallout method under MapView.Marker but not having luck.

I've set the ref="myMarker" on a marker during render, and then in componentWillMount stage, use this.refs.myMarker.showCallout() but nothing seems to happen on the map. There's no error logged either.

Not sure if my usage is incorrect as I could not find an example usage in the folders. Is there a more detailed description on how to properly use the method?

Thanks

example project issue Android

First, thanks for this MapView component, I really love it!

I tried to run the example project, it's working perfect on iOS, but Android has some issues.

For "Tracking Position", not able to move map and zoom, but working fine on "Arbitary Views as Markers",
"Events" has the same problem.

PruneCluster

Hi.
Is it possible to add PruneCluster for markers?

Create a `FeatureCollection` component that encourages composition

The API of this library, which works by having the children of the <MapView /> component does a great job making maps and map features more "React-like", but it could go a bit further.

Right now, it is possible to make composable react components that end up rendering a single feature (like marker), and passing them as children to the map view

const FooMarker = ({ foo }) => (
  <MapView.Marker coordinate={foo.coordinate}>
    <View styles={styles.fooContainer}>
      {...}
    </View>
  </MapView.Marker>
);

const MapScene = ({ foo }) => (
  <MapView {...}>
    <FooMarker foo={foo} />
  </MapView>
);

However, as soon as we want to render more than one feature and compose, it wont work... because react requires every component to return a single node, and thus you would need to "wrap" the features in something, but still end up adding them to the mapview as direct children.

The API I'm envisioning could go something like this:

const Foo = ({ foo }) => (
  <MapView.FeatureCollection>
    {/* render a custom marker for the `foo` */}
    <MapView.Marker coordinate={foo.coordinate}>
      <View styles={styles.fooContainer}>
        {...}
      </View>
    </MapView.Marker>
    {/* also render a circle under the marker based on foo's properties */}
    <MapView.Circle 
      center={foo.coordinate}
      radius={foo.reach}
      fillColor={fooColorFromType(foo.type)}
    />
  </MapView.FeatureCollection>
);

const MapScene = ({ foo }) => (
  <MapView {...}>
    <Foo foo={foo} />
  </MapView>
);

This could allow for limitless composition of map features, and much better separation of concerns

This might require some acrobatics on the native side, but I think it would be worth it.

How would one mark out specific streets

This plugin looks impressive. I've been fiddling with a app-idea that's centered around a map, I need to 'mark out streets'. So not setting a marker but rather color whole streets making them stand out on the map. Is this something that can be done with react-native-maps? Maybe with the Polyline? I couldn't find the answer while checking out the readme and docs.

Make callout visibility controlled / declarative

This is a similar wish to this:
facebook/react-native#4656

I understand that we have the showCallout method but this seems to be an imperative way to do so, plus it needs to know when the marker is rendered, etc.

I would expect something like this (showsCalloutOnLoad property):

                        <MapView.Marker
                            key={marker.key}
                            coordinate={marker.coordinate}
                            title={marker.title}
                            description={marker.description}
                            showsCalloutOnLoad
                        />

If more than one marker uses this property then only one of them shows the callout (the last one loaded?), since you do not support multiple open callouts. Obviously, we can have checks to make sure that only the marker that interests the user will have this property as true on render.

Add `id` prop for markers to be passed back in all events

This would make the event handlers on the mapview much more useful since you could know which marker was causing the event. This would also help performance when you need to have a ton of markers, but don't want to have a ton of bound event handler functions.

No map displayed

Installation and compilation work fine, but nothing is displayed (neither tiles or markers or shapes) on Android

Map isn't updating on region prop change

I've been trying to run the sample you gave in the readme but couldn't make it work.

getInitialState() {
  return {
    region: {
                longitudeDelta: 18.162189759314053,
                latitudeDelta: 16.288021267949482,
                longitude: 53.07996740564704,
                latitude: 55.27790853263076
            }
  };
}

onRegionChange(region) {
  this.setState({ region });
}

render() {
  return (
    <MapView 
      region={this.state.region}
      onRegionChange={this.onRegionChange}
    />
  );
}

The map isn't changing according to the region in the state.

I debugged the Android project and noticed that the setRegion method not gets called.

I'm running with RN: 0.19.0

Configuration with name 'default' not found.

The example project runs OK but when I apply the module to a fresh new project or an existing RN 0.17 project I get this error when compiling for Android:

A problem occurred configuring project ':app'.
> Cannot evaluate module react-native-maps : Configuration with name 'default' not found.

Can't seem to get this working on Android, just get a white background

I've tried it by copying all code from the example\app.js down into a new react native app with react-native-maps setup as per the application instructions. I also have put the api key in the app.manifest and followed the instructions to install google play. I am using genymotion free with a custom phone 5.1.0 -api 22 image.

It maybe due to the fact that the Google Apps zip would not flash. can you confirm this as the problem and what I can do about it.

How to run the project example?

I'm anxiously waiting for this to get to npm!

Meanwhile I've copied the project files, run npm install and when I run the project in iOS I get an error:
'Image' has no propType for native prop RCTImageView.defaultImageSrc of native type UIImage.
image

In Android, when I run "react-native run-android" I get an error:
" > Could not find com.google.android.gms:play-services-base:8.3.0."
" > Could not find com.google.android.gms:play-services-maps:8.3.0."

What am I doing wrong?

Initial Postion bases on geolocation

Hi, Everyone,
I'm not sure if I should write this question on here.

On my app, I did this on render:

<MapView 
          style = {styles.mapView}
          initialRegion={this.state.currentRegion}
          showsUserLocation = {true}
          ))}

and I have this to get user's current position:

componentDidMount: function() {
    navigator.geolocation.getCurrentPosition(
      (position) => {
       console.log(position);
        this.setState({currentRegion: {
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          latitudeDelta: LATITUDE_DELTA,
          longitudeDelta: LONGITUDE_DELTA,
        }});
      },
      (error) => alert(error.message),
      {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
    );
    this.watchID = navigator.geolocation.watchPosition((position) => {
       console.log(position);
      this.setState({currentRegion: {
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          latitudeDelta: LATITUDE_DELTA,
          longitudeDelta: LONGITUDE_DELTA,
        }});

    })

But with this, It's didn't auto move to current region on Android, but on iOS it'll move to current region when open that page.

Thanks.

Could not find com.google.android.gms:play-services-base:8.3.0

Hello, this bunch or errors i see just after react-native run-android. I am new to react-native, so not sure whether I missed something or this is bug.

Should I define something in build.gradle? I 've tried to install Google Play Services in Android SDK. And provided compile "com.google.android.gms:play-services-base:8.3.0", unfortunately it still fails.
So what did I miss?

> A problem occurred configuring project ':react-native-maps'.
   > Could not resolve all dependencies for configuration ':react-native-maps:_debugCompile'.
      > Could not find com.google.android.gms:play-services-base:8.3.0.
        Searched in the following locations:
            file:/home/fly/.m2/repository/com/google/android/gms/play-services-base/8.3.0/play-services-base-8.3.0.pom
            file:/home/fly/.m2/repository/com/google/android/gms/play-services-base/8.3.0/play-services-base-8.3.0.jar
            https://jcenter.bintray.com/com/google/android/gms/play-services-base/8.3.0/play-services-base-8.3.0.pom
            https://jcenter.bintray.com/com/google/android/gms/play-services-base/8.3.0/play-services-base-8.3.0.jar
            file:/home/fly/third_party_software/android-sdk-linux/extras/android/m2repository/com/google/android/gms/play-services-base/8.3.0/play-services-base-8.3.0.pom
            file:/home/fly/third_party_software/android-sdk-linux/extras/android/m2repository/com/google/android/gms/play-services-base/8.3.0/play-services-base-8.3.0.jar
        Required by:
            time24_mobile:react-native-maps:unspecified
      > Could not find com.google.android.gms:play-services-maps:8.3.0.
        Searched in the following locations:
            file:/home/fly/.m2/repository/com/google/android/gms/play-services-maps/8.3.0/play-services-maps-8.3.0.pom
            file:/home/fly/.m2/repository/com/google/android/gms/play-services-maps/8.3.0/play-services-maps-8.3.0.jar
            https://jcenter.bintray.com/com/google/android/gms/play-services-maps/8.3.0/play-services-maps-8.3.0.pom
            https://jcenter.bintray.com/com/google/android/gms/play-services-maps/8.3.0/play-services-maps-8.3.0.jar
            file:/home/fly/third_party_software/android-sdk-linux/extras/android/m2repository/com/google/android/gms/play-services-maps/8.3.0/play-services-maps-8.3.0.pom
            file:/home/fly/third_party_software/android-sdk-linux/extras/android/m2repository/com/google/android/gms/play-services-maps/8.3.0/play-services-maps-8.3.0.jar
        Required by:
            time24_mobile:react-native-maps:unspecified

PS: Thanks for your work, long live open source

Issue with react-native 0.19

Not sure if I'm doing something wrong but with RN 0.19 props does not seems to be passed into the native components in Android.

I tried to render a MapMarker and it raised an error, I removed it and noticed that even my Map region was not set properly, I tried to debug it and it seem to not call the ReactProps setters.

Might be related to facebook/react-native#5649? Tried to change the imports but it didn't resolved it.

Does it work fine with you ?

screen shot 2016-01-31 at 2 22 22 pm

Blank screen on usage

Hi there, first of all thanks for the great work.

A question though: when implementing react-native-apps, and i use rnpm link, the project files are added to my project, but when running the code, i gives me a blank screen without any error what so ever, not i xcode , not in the chrome debugger.

(Find the libairmaps.a file) blank screen remains.

Any suggestions?

Error: Animated.multiply is not a function

First off, nice work and MERCI!

When I run 'Animating with MapViews' exemple on iOS (Simulator) I get this error ->"Animated.multiply is not a function. (In 'Animated.multiply(isIndex,panY)', 'Animated.multiply' is undefined)"

Ideas ?

Polygon events

It is possible to add an event when a Polygon is pressed?

Do components provide JavaScript APIs or SDK APIs?

Hello,
First of all, thanks for these awesome components.

Could you please tell me whether the components use native SDK parts or not?

This is important because of payment issues. Google specifies the price of Google Maps API's usage as "Unlimited free usage" for Google Maps Android API. But JavaScript API usage is not free.

If only I could figure out from source code or Installation Instructions the answer of this question. Unfortunately I'm new in Native applications.

Marker image

Hi,
Is it possible to assign a new image to a marker onSelect event?
Thanks!! :)

Animated.Region undefined constructor

I may be missing something. How is Animated.Region supposed to be referenced? I can't seem to get it bundled at all. It isn't one of the module.exports. I see it in the examples, but can't use it in my project.

Any help is appreciated!

Error trying to run the AnimatedViews example

When trying to run the example on iOS, I get the following error :
undefined is not a constructor (evaluating 'new Animated.Region({latitude: ....})'), that is thrown line 196 of the AnimatedViews example... I can't figure what I'm doing wrongly..

Dashed Polyline Support

Can we have dashed polylines somehow? I understand that this is not possible at the moment but could that be possible?

image

onMarkerPress event is bubbled up to parent components onPress events

Hi! I'm using MapView inside one of the views that is inside TabBar. It looks something like this:

<TabBarIOS>
  <TabBarIOS.Item onPress={this.handleTabBarItemPress}>
    <View>
      <Mapview>
        <MapView.Marker></MapView.Marker>
      </Mapview>
    </View>
  </TabBarIOS.Item>
</TabBarIOS>

Now when pressing on MapView.Marker, handleTabBarItemPress method gets called, even without adding any event handlers to marker element itself. The event.nativeEvent.action has "marker-press" as value. Luckily, this is my current workaround how i can bypass handling this event handler :)

Also i'd like to take a chance and thank you guys for converting this repository into library. I seriously needed working map view for Android this week and it could not come at a better time than it is. I hope i get a chance to contribute to this repository as well. Cheers!

Doesn't work on Android

Here is my component:

import React from 'react-native'
const {View, Text, ScrollView, Dimensions, StyleSheet} = React
import {observe} from 'JB/observeMixin'
import connectToStores from 'JB/connect'
import MapView from 'react-native-maps';


var { width, height } = Dimensions.get('window');

const ASPECT_RATIO = width / height;
const LATITUDE = 37.78825;
const LONGITUDE = -122.4324;
const LATITUDE_DELTA = 0.0922;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;


let hocs = compose(
  observe(loggedInUser$)
,
  connectToStores({
    jobs: 'employer.jobs',
    profile: 'user.profile',
  }, {
    changePage,
  })
)
export default hocs(class EmployerDashboard extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      hidemap: false,
      region: {
        latitude: LATITUDE,
        longitude: LONGITUDE,
        latitudeDelta: LATITUDE_DELTA,
        longitudeDelta: LONGITUDE_DELTA,
      },
    }
  }

  componentDidMount() {
    unfinishedJobs = [];
  }
  componentDidUpdate(prevProps, prevState) {
    unfinishedJobs = [];
  }

  // map example methods
  onRegionChange(region) {
    this.setState({ region });
  }

  jumpRandom() {
    this.setState({ region: this.randomRegion() });
  }

  animateRandom() {
    this.refs.map.animateToRegion(this.randomRegion());
  }

  randomRegion() {
    var { region } = this.state;
    return {
      ...this.state.region,
      latitude: region.latitude + (Math.random() - 0.5) * region.latitudeDelta / 2,
      longitude: region.longitude + (Math.random() - 0.5) * region.longitudeDelta / 2,
    };
  }


  render() {
    const {profile, jobs, Actions} = this.props
    const {hidemap} = this.state

    const goToPage = (...args) => _ => Actions.changePage(...args)
    const toggleMap = _ => this.setState({ hidemap: !hidemap })
    console.log('MapView', MapView)
    return (
      <View style={{
        position: 'absolute',
        top: 0,
        left: 0,
        right: 0,
        bottom: 0,
        justifyContent: 'flex-end',
        alignItems: 'center',
        backgroundColor: 'green'
      }}>

          <MapView
            ref="map"
            style={{
              position: 'absolute',
              top: 0,
              left: 0,
              right: 0,
              bottom: 0,
              backgroundColor: 'red'
            }}
            region={this.state.region}
            onRegionChange={this.onRegionChange.bind(this)}
          >
          </MapView>


          <MaterialButtonFixed 
            onPress={ goToPage('employer.hire', {unfinishedJobs}) }
            text='HIRE!'
          />

      </View>
    )
  }
})

"react": "^0.14.6",
"react-native": "^0.18.0",
"react-native-maps": "^0.2.3",

right now it works in iOS properly. In android i see only green background of the View container, nothing else

Also, please, mention in the installation guide that developer should have Google Play Services, Google Play Repository and Google Play APK Expansion Library installed in the android SDK.

By the way, may be I should have some other dependencies installed and this is the reason, why the map is not displayed in android in my case?

calling showCallout() triggers onMarkerSelect() event?

Upon calling showCallout() on a Maview Marker ref, I seem to receive the event onMarkerSelect() for that marker. The result is that the callout is selected twice (redrawn twice) Is this the current intended behavior? If so, is there a way to disable the even generation? Since calling showCallout() explicitly means I'm already aware of the marker selection and do not need it to be selected again.

Android map view calls onLayout when adding a new child

It seems that MapView._onLayout is called multiple times when updating the markers. It does not happen for iOS only for Android.

This cause an issue that it repositions the map to the initialRegion everytime, not sure in Android what triggers the onLayout call.

I have currently a workaround in the component that uses MapView which is that after the first load to not return the initialRegion prop anymore.

The best would be to fix this in Android but it's also possible to fix this in JS ( set a boolean on componentDidMount and set it / check it in _onLayout, unless you think of other issues this could cause ) I could do a PR for that if you want.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.