This project demonstrates how to implement self-tracking functionality using the Roam SDK in a React Native application. It serves as a reference for developers looking to integrate location tracking features into their own applications.
- Request and check location permissions
- Start and stop location tracking
- Display real-time location updates
- Show tracking status
- Implement foreground service for continuous tracking on Android
- Node.js (v12 or newer)
- npm or yarn
- React Native CLI
- Android Studio (for Android development)
- Xcode (for iOS development, macOS only)
- A Roam SDK API key (sign up at Roam's website)
git clone https://github.com/your-username/roam-react-native-example-self-tracking.git
cd roam-react-native-example-self-tracking
# using npm
npm install
# OR using Yarn
yarn install
- Open
android/app/src/main/java/com/roamreactnativeexampleselftracking/MainApplication.java
- Replace
YOUR_ROAM_SDK_KEY
with your actual Roam SDK key:Roam.initialize(this, "YOUR_ROAM_SDK_KEY");
- For Android:
npx react-native run-android
- For iOS (work in progress):
npx react-native run-ios
You've successfully run the Roam Location SDK with Self Tracking. 🥳
Note: iOS implementation is still a work in progress and may not function correctly at this time.
-
Permission Handling: The app first checks and requests necessary location permissions.
-
Start Tracking: When the user presses "Start Tracking", the app:
- Enables foreground notification (on Android)
- Starts location tracking using Roam SDK
- Begins listening for location updates
- Location Display: As location updates are received, the app displays:
- Latitude and Longitude
- Accuracy
- Altitude
- Speed
- Activity type
- Timestamp
- Timezone
- Stop Tracking: When the user presses "Stop Tracking", the app:
- Stops location tracking
- Disables foreground notification (on Android)
- Clears the displayed location data
To implement self-tracking in your own app using this example:
- Set up the Roam SDK in your project.
- Copy the permission handling logic.
- Implement the start and stop tracking functions.
- Set up a listener for location updates.
- Display or process the received location data as needed.
- Add LocationService.java. Refer the file
android/app/src/main/java/com/roamreactnativeexampleselftracking/LocationService.java
- Update AndroidManifest.xml with the above service.
Remember to handle edge cases, such as permission denials and location services being disabled.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.