-
Notifications
You must be signed in to change notification settings - Fork 0
Quickstart
The GeoSpark React Native SDK makes it quick and easy to build a location tracker for your React Native app. We provide powerful and customizable tracking modes and features that can be used to collect your users location updates.
In your project directory, install from npm, and then link it.
$ npm install react-native-geospark --save
$ react-native link react-native-geosparkiOS
Install using Cocoapods, open podfile and add SDK to file.
pod 'GeoSpark'Once you have updated your podfile, **** run pod install in your
terminal.
Configure project
To configure the location services, add following entries to the Info.plist file.

Then, in your project settings, go to Capabilities > Background Modes
and turn on background fetch, location updates, remote-notifications.

Then, go to Build Settings in the project targets and change 'Always Embed Swift Standard Libraries' to 'Yes'.
Manual Linking
-
Open the iOS module files, located inside
node_modules/react-native-geospark/ios/. -
Open the app workspace file
(AppName.xcworkspace)in Xcode. -
Move the
RNGeoSpark.handRNGeoSpark.mfiles to your project. When shown a popup window, select Create groups.
Android
Install the SDK to your project via Gradle in Android Studio, add the
dependencies below in your app build.gradle file.
dependencies {
implementation 'com.geospark.android:geospark:3.0.4'
}Import the module in App.js file
import GeoSpark from 'react-native-geospark'; Android
Initialize the SDK with your publishable key.
//In onCreate method of your Application class include the code below.
public class MainApplication extends Application implements ReactApplication {
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
GeoSpark.initialize(this, "PUBLISH_KEY");
}
}; iOS
Import GeoSpark into your AppDelegate file.
Swift
import GeoSparkObjective-C
#import <GeoSpark/GeoSpark.h>Initialize the SDK in your AppDelegate class before calling any other
GeoSpark methods under this
application:didFinishLaunchingWithOptions:
Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeoSpark.intialize("PUBLISHABLEKEY")
return true
}Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeoSpark intialize:@"PUBLISHABLEKEY"];
return YES;
}Get location permission from the App user on the device. Also check if the user has turned on location services for the device. In addition, get motion permission for iOS.
// Call this method to check Location Permission for Android & iOS
GeoSpark.checkLocationPermission( status => {
// do something with status
});
// Call this method to request Location Permission for Android & iOS
GeoSpark.requestLocationPermission();Android
// Call this method to check Location services for Android
GeoSpark.checkLocationServices( status => {
// do something with status
});
// Call this method to request Location services for Android
GeoSpark.requestLocationServices();To start tracking the location above Android 10
// Call this method to check background location permission for Android
GeoSpark.checkBackgroundLocationPermission( status => {
// do something with status
});
// Call this method to request background location Permission for Android
GeoSpark.requestBackgroundLocationPermission();GeoSpark has three default tracking modes along with a custom version. They differ based on the frequency of location updates and battery consumption. The higher the frequency, the higher is the battery consumption. Android you must use foreground service for continuous tracking.
| Mode | Battery usage | **Updates every ** | **Optimised for/advised for ** |
| Active | 6% - 12% | 25 ~ 250 meters | Ride Hailing / Sharing |
| Reactive | 3% - 6% | 50 ~ 500 meters | On Demand Services |
| Passive | 0% - 1% | 100 ~ 1000 meters | Social Apps |
Use the tracking modes while you use the startTracking method
GeoSpark.startTracking or GeoSpark.startSelfTracking
Example:
For reference check our sample app : https://github.com/geosparks/geospark-react-native-example
//cloud integration
//active tracking
GeoSpark.startTracking(GeoSpark.TrackingMode.ACTIVE);
// reactive tracking
GeoSpark.startTracking(GeoSpark.TrackingMode.REACTIVE);
// active tracking
GeoSpark.startTracking(GeoSpark.TrackingMode.ACTIVE);
//self-managed integration
//active tracking
GeoSpark.startSelfTracking(GeoSpark.TrackingMode.ACTIVE);
// reactive tracking
GeoSpark.startSelfTracking(GeoSpark.TrackingMode.REACTIVE);
// active tracking
GeoSpark.startSelfTracking(GeoSpark.TrackingMode.ACTIVE);The SDK also allows you define a custom tracking mode that allows you to customize and build your own tracking modes.
Android
| Type | Unit | Unit Range |
|---|---|---|
| Distance Interval | Meters | 1m ~ 2500m |
| Time Interval | Seconds | 10s ~ 10800s |
Distance between location updates example code:
//Update location based on distance between locations.
//cloud integration
GeoSpark.startTrackingDistanceInterval("DISTANCE IN METERS", "STATIONARY DURATION IN SECONDS",
GeoSpark.DesiredAccuracy.HIGH);
//self-managed integration
GeoSpark.startSelfTrackingDistanceInterval("DISTANCE IN METERS", "STATIONARY DURATION IN SECONDS",
GeoSpark.DesiredAccuracy.HIGH);Time between location updates example code:
//Update location based on time interval.
//cloud integration
GeoSpark.startTrackingTimeInterval("INTERVAL IN SECONDS", GeoSpark.DesiredAccuracy.HIGH);
//self-managed integration
GeoSpark.startSelfTrackingTimeInterval("INTERVAL IN SECONDS", GeoSpark.DesiredAccuracy.HIGH);iOS
//cloud integration
GeoSpark.startTrackingCustom(allowBackground,pauseAutomatic,activityType,
desiredAccuracy,showBackIndicator,distanceFilter)
//self-managed integration
GeoSpark.startSelfTrackingCustom(allowBackground,pauseAutomatic,activityType,
desiredAccuracy,showBackIndicator,distanceFilter)Example
//cloud integration
GeoSpark.startTrackingCustom(true,true,GeoSpark.ActivityType.FITNESS,
GeoSpark.DesiredAccuracyIOS.BEST,true,10)
//cloud integration
GeoSpark.startSelfTrackingCustom(true,true,GeoSpark.ActivityType.FITNESS,
GeoSpark.DesiredAccuracyIOS.BEST,true,10)Related guides:
-
Cloud Integration
Cloud integration is when we manage your data through our servers providing you a system of tools and technologies that connects various applications and systems for the real-time exchange of location data and processes including Insights, Trips, Geofencing and Nearby APIs.”or”
-
Self-Managed Integration
Self-managed integration is when you manage your data by sending all location data back to your server from the SDK directly without communicating to our server. This allows you to keep complete privacy of your data and manage your security standards.