https://github.com/woosmap/geofencing-example-android
Initial commit
https://github.com/woosmap/geofencing-example-android
Last synced: about 1 month ago
JSON representation
Initial commit
- Host: GitHub
- URL: https://github.com/woosmap/geofencing-example-android
- Owner: Woosmap
- Created: 2023-10-06T10:50:31.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-28T15:23:07.000Z (over 2 years ago)
- Last Synced: 2025-12-26T21:14:40.186Z (6 months ago)
- Language: Kotlin
- Size: 173 KB
- Stars: 0
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Woosmap Geofencing SDK Example for Android
The Woosmap Geofencing SDK is a mobile software development kit focused on gathering efficiently the users’ location, triggering events based on region monitoring, and providing categorized users’ zones of interest from geographical and temporal clusters.
The SDK simplifies the integration of the location context in your mobile application by taking care of lower-level functionalities such as data collection or battery management.
## Documentation
All feature descriptions and guides to implement the Woosmap Geofencing Android SDK are available on the [Woosmap developers documentation](https://developers.woosmap.com/products/geofencing-sdk/get-started/).
## Getting Started
### Setup Your Account
When you [sign up](https://www.woosmap.com/en/sign_up?utm_campaign=Woosmap+Sign-up&utm_source=Developers-documentation) for a Woosmap account, you’ll enter your login/password and an email address, and we’ll send you an activation email.
In the activation email, click on the link to activate your account. Once you activate the account login to [Woosmap Console](https://console.woosmap.com/) and follow the steps below.
* [Create An Organization](https://developers.woosmap.com/get-started/#create-an-organization)
* [Create A Project And API Keys](https://developers.woosmap.com/get-started/#create-a-project-and-api-keys)
* [Register a Woosmap Private API key](https://developers.woosmap.com/support/api-keys/#registering-a-woosmap-private-api-key)
## Example
### Load assets in the Woosmap platform and enable Store Search API
In this repository, a sample code is provided for testing quickly the Geofencing Android SDK. Once this code built, a sample app allows you to monitor Point of Interest (previously loaded in the Woosmap Platform). Before runing the example, each POI has to be created as an asset in the Woosmap Console and the Store Search API must be enabled:
**Create an asset for each POI you want to monitor with a geofence**

**Enable Woosmap Store Search API**

### Run the sample app
To run the example, first clone this repository and replace the private key in `res/strings.xml` with your own private key. Make sure you have secured your private key.
The sample application has four components.
* List of locations obtained from `LocationReadyCallback` callback of `LocationReadyListener`.
* List of events obtained using `RegionLogReadyCallback` callback of `RegionLogReadyListener`.
* A floating action button that starts and stops tracking.
* A floating action button that clears all the data from local SQLite DB.



### Permissions
Sample app also shows how to request `ACCESS_COARSE_LOCATION` and `ACCESS_FINE_LOCATION` permissions. For optimal experience, it is also desired that the app has `ACCESS_BACKGROUND_LOCATION` permission granted.
If you wish to [track BLE beacons](https://developers.woosmap.com/products/geofencing-sdk/android-sdk/guides/monitor-beacons/) then it is advised that the Bluetooth permissions are granted as well.
Since the sample app posts notifications when user location transitions between Geofence Regions, it is advised that the app should also request `POST_NOTIFICATIONS` permissions (Required only on Android 13 and above).
### Fetching locations
In the sample app, a list of locations is populated using `LocationReadyCallback`. Whenever the SDK reports a new location, it is appended to the list. However, these locations are also stored in a local SQLite database. To fetch these locations you can use the following code.
```kotlin
// Get all positions
val movingPositions = WoosmapDb.getInstance(
applicationContext
).movingPositionsDao.getMovingPositions(-1)
// Observe for only newly added locations
val movingPositionList = WoosmapDb.getInstance(applicationContext).movingPositionsDao.getLiveDataMovingPositions(-1)
movingPositionList.observe(this) { movingPositions ->
Log.d(
"MyApplication",
"Newly obtained location length is ${movingPositions.size} "
)
}
```
### Fetching region logs
Sample app depends on `LocationReadyCallback` of `RegionLogReadyListener` interface to determine the entry and exit events of the Geofence regions. When user location transitions inside a Geofence region, `LocationReadyCallback` is invoked along with an object of `RegionLog` which helps to determine if the region was entered or exited. The same callback is invoked when the user location moves outside a Geofence region. These transition logs (`RegionLogs`) are also stored in the local SQLite database. To fetch these `RegionLogs` use the following,
```kotlin
// Get all region logs
val regionLogs = WoosmapDb.getInstance(applicationContext).regionLogsDAO.allRegionLogs
// Observe newly added region logs
val liveRegionLogs = WoosmapDb.getInstance(applicationContext).regionLogsDAO.allLiveRegionLogs
liveRegionLogs.observe(
this
) { regionLogs ->
Log.d(
"MyApplication",
"Newly added region log length is ${regionLogs.size}"
)
}
```