Plugin integration
The Magic Lane Maps SDK for React Native is built on top of the TypeScript SDK, providing the same powerful mapping features with a native React Native component for rendering maps.
The React Native plugin shares nearly all functionality with the TypeScript SDK. The only distinction lies in how the map view is created and rendered, using the GLView component. Everything else - APIs, features, and functionality covered in the TypeScript SDK documentation - applies to React Native as well.
Installation
Install both the core Maps SDK and the React Native adapter:
Using npm
npm install @magiclane/maps-sdk @magiclane/maps-sdk-react-native
Using yarn
yarn add @magiclane/maps-sdk @magiclane/maps-sdk-react-native
Using pnpm
pnpm add @magiclane/maps-sdk @magiclane/maps-sdk-react-native
Get Your API Token
To use the Maps SDK, you need an API token from Magic Lane.
- Visit the Magic Lane Developer Portal
- Sign up or log in to your account
- Create a new project or select an existing one
- Copy your API token from the project dashboard
Keep your API token secure! Never commit it directly to version control. Use environment variables or a secure configuration management solution.
Basic Setup
Initialize the SDK
Before creating the map view, you need to initialize the SDK with your API token:
import {
GemKitPlatform,
SdkSettings,
IGemKitPlatform
} from '@magiclane/maps-sdk';
import { GemKitNativeReact } from '@magiclane/maps-sdk-react-native';
// Initialize the platform (do this once in your app)
let gemKitInstance;
if (IGemKitPlatform.getInstance() == null) {
gemKitInstance = new GemKitNativeReact();
GemKitPlatform.getInstance(gemKitInstance);
} else {
gemKitInstance = IGemKitPlatform.getInstance();
}
// Load the native module and set authorization
GemKitPlatform.getInstance().loadNative();
SdkSettings.appAuthorization = "YOUR_API_TOKEN_HERE";
On Android, you may need to delay initialization slightly to ensure native modules are ready:
if (Platform.OS === 'android') {
setTimeout(init, 2000);
} else {
init();
}
Create the Map View
The key difference in React Native is using the GLView component instead of creating a DOM element:
import { GLView } from '@magiclane/maps-sdk-react-native';
<GLView
style={{ flex: 1 }}
onMapReady={(event) => {
if (event.gemMap) {
// Map is ready - you can now interact with it
const map = event.gemMap;
console.log('Map initialized successfully!');
}
}}
/>
The GLView component is the React Native equivalent of the web SDK's map container. It handles all the native rendering and provides a gemMap instance through the onMapReady callback.
Component Props
The GLView component accepts the following props:
| Prop | Type | Description |
|---|---|---|
style | ViewStyle | React Native style object for the view container |
onMapReady | (event: { gemMap: GemMap }) => void | Callback fired when the map is initialized and ready |
Using the Rest of the SDK
Once you have the gemMap instance from onMapReady, you can use all the features documented in the TypeScript SDK:
- Maps: Display maps, adjust map views, handle gestures
- Search: Search for places, geocoding
- Routing: Calculate routes, display routes on map
- Navigation: Turn-by-turn navigation
- Positioning: Location services, show location on map
Complete Example
See the React Native Hello World example for a complete, working implementation.
Platform Requirements
iOS
- iOS 13.0 or higher
- Xcode 14.0 or higher
Android
- Android API level 24 (Android 7.0) or higher
- Android SDK 33 or higher
Next Steps
- Check out the Hello World Example
- Explore Maps
- Learn about Search & Places
- Implement Routing & Navigation