Convert Figma logo to code with AI

nitaliano logoreact-native-mapbox-gl

A Mapbox GL react native module for creating custom maps

2,167
694
2,167
225

Top Related Projects

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL

React Native Mapview component for iOS + Android

Quick Overview

React Native Mapbox GL is a library that provides a React Native wrapper for Mapbox GL Native SDK. It allows developers to integrate high-performance vector maps into their React Native applications, offering a wide range of customization options and features for creating interactive map experiences.

Pros

  • Seamless integration with React Native, allowing for easy implementation of maps in mobile apps
  • High performance and smooth rendering of vector maps
  • Extensive customization options for map styles, annotations, and interactions
  • Access to Mapbox's powerful geospatial features and data

Cons

  • Requires a Mapbox account and API key, which may involve costs for high-usage applications
  • Learning curve for developers unfamiliar with Mapbox GL or geospatial concepts
  • Limited documentation and community support compared to some other mapping libraries
  • Potential compatibility issues with certain React Native versions or other libraries

Code Examples

  1. Adding a basic map to a React Native component:
import React from 'react';
import MapboxGL from '@react-native-mapbox-gl/maps';

MapboxGL.setAccessToken('YOUR_MAPBOX_ACCESS_TOKEN');

const Map = () => (
  <MapboxGL.MapView style={{flex: 1}}>
    <MapboxGL.Camera
      zoomLevel={12}
      centerCoordinate={[-122.4324, 37.7882]}
    />
  </MapboxGL.MapView>
);

export default Map;
  1. Adding a marker to the map:
import MapboxGL from '@react-native-mapbox-gl/maps';

// ... inside your component
<MapboxGL.MapView style={{flex: 1}}>
  <MapboxGL.PointAnnotation
    id="marker"
    coordinate={[-122.4324, 37.7882]}
  >
    <View style={{width: 30, height: 30, backgroundColor: 'red', borderRadius: 15}} />
  </MapboxGL.PointAnnotation>
</MapboxGL.MapView>
  1. Handling map press events:
import MapboxGL from '@react-native-mapbox-gl/maps';

const handleMapPress = (event) => {
  const { geometry } = event;
  console.log('Pressed at coordinates:', geometry.coordinates);
};

// ... inside your component
<MapboxGL.MapView onPress={handleMapPress} style={{flex: 1}}>
  {/* Map content */}
</MapboxGL.MapView>

Getting Started

  1. Install the library:

    npm install @react-native-mapbox-gl/maps
    
  2. For iOS, install pods:

    cd ios && pod install
    
  3. Set up your Mapbox access token in your app's entry file:

    import MapboxGL from '@react-native-mapbox-gl/maps';
    MapboxGL.setAccessToken('YOUR_MAPBOX_ACCESS_TOKEN');
    
  4. Use the MapboxGL.MapView component in your React Native app as shown in the code examples above.

Competitor Comparisons

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL

Pros of mapbox-gl-native

  • Native performance and optimizations for each platform
  • Direct access to lower-level APIs and features
  • More control over map rendering and customization

Cons of mapbox-gl-native

  • Steeper learning curve for developers
  • Requires platform-specific knowledge (iOS, Android, etc.)
  • More complex integration with React Native projects

Code Comparison

mapbox-gl-native (Objective-C):

MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:mapView];

react-native-mapbox-gl (JavaScript):

import MapboxGL from '@react-native-mapbox-gl/maps';

<MapboxGL.MapView
  style={{flex: 1}}
  styleURL={MapboxGL.StyleURL.Street}
/>

The mapbox-gl-native repository provides native implementations for various platforms, offering better performance and more direct access to platform-specific features. However, it requires more expertise in native development and can be more challenging to integrate with React Native projects.

On the other hand, react-native-mapbox-gl offers a more straightforward integration with React Native, using a JavaScript API that's familiar to React developers. While it may not provide the same level of performance or customization as the native implementation, it allows for faster development and easier cross-platform compatibility.

React Native Mapview component for iOS + Android

Pros of react-native-maps

  • Free and open-source, with no usage limits or API key requirements
  • Supports both Google Maps and Apple Maps, providing flexibility for different platforms
  • Large community support and frequent updates

Cons of react-native-maps

  • Limited customization options compared to Mapbox GL
  • Performance can be slower, especially with complex map interactions
  • Less advanced features for data visualization and styling

Code Comparison

react-native-maps:

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

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

react-native-mapbox-gl:

import MapboxGL from '@react-native-mapbox-gl/maps';

<MapboxGL.MapView
  styleURL={MapboxGL.StyleURL.Street}
  zoomLevel={15}
  centerCoordinate={[-122.4324, 37.78825]}
>
  <MapboxGL.PointAnnotation
    id="marker"
    coordinate={[-122.4324, 37.78825]}
  />
</MapboxGL.MapView>

Both libraries offer similar basic functionality, but react-native-mapbox-gl provides more advanced features and customization options at the cost of requiring an API key and potentially incurring usage fees.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Deprecation notice

This repository is no longer actively maintained.

Continued development of react-native-mapbox-gl may be found in the community driven repository at https://github.com/react-native-mapbox-gl/maps. This new repository uses the latest versions of the Mapbox SDKs for iOS and Android, and contains a long range of improvements over the current one. We recommend you review the changelog for the new repository and transition to it.

This repository will only accept PRs containing bug fixes. Any new feature development will happen in the new repository.

Mapbox Maps SDK for React Native

An unofficial React Native component for building maps with the Mapbox Maps SDK for iOS and Mapbox Maps SDK for Android

npm version FOSSA Status

What is Mapbox?

Mapbox is the location data platform for mobile and web applications. We provide building blocks to add location features like maps, search, and navigation into any experience you create. Use our simple and powerful APIs & SDKs and our open source libraries for interactivity and control.

Sign up for Mapbox

Not a Mapbox user yet? Sign up for an account here. Once you’re signed in, all you need to start building is a Mapbox access token. Use this same short code with all of our interactive mapping libraries, Python and JavaScript SDKs, and directly against our REST APIs. You can create and manage your access tokens on your Mapbox Account page.

Installation

🛑 NB: The current release 6.1.4 is not up on NPM. You have to get the master version from github. 🛑

Dependencies

Git

git clone git@github.com:mapbox/react-native-mapbox-gl.git
cd react-native-mapbox-gl

Yarn

yarn add https://github.com/nitaliano/react-native-mapbox-gl#master

Npm

npm install https://github.com/nitaliano/react-native-mapbox-gl/tarball/master

Installation Guides

Documentation

Components

Sources

Layers

Offline

Expo Support

We have a feature request open with Expo if you want to see it get in show your support https://expo.canny.io/feature-requests/p/add-mapbox-gl-support

Developer Group

Have a question or need some help? Join our Gitter developer group!

License

FOSSA Status

NPM DownloadsLast 30 Days