Step 1: Install SDK
Open Android Studio, start a new Android Studio project and create a project.
Select minimum SDK Android 4.1.
Select Empty Activity and finish.
Install the SDK to your project via Gradle in Android Studio and add the dependencies below in your app build.gradle file.
Step 2: Set DeviceToken
Set FCM DeviceToken to create a user. If you haven't set FCM DeviceToken already, then add Firebase to your Android project.
Step 3: Initialize SDK
Sign up here to create an account with GeoSpark. Post signup, you can create your first project from the dashboard screen.
Once you have created your project, you can add App Name, Package Name and create Android applications. You can get the publishable key from your project settings page which has to be used while integrating the SDK with your application.
In onCreate method of your Application class, Initialize the SDK with your PublishableKey.
Step 4: Create GetStartedActivity.java
Create getstartedactivity.xml and add a TextView.
Now create a GetStartedActivity.java and add GeoSpark createUser() method inside your onClickListener of the Button, to create a user which returns UserID. The SDK needs a UserID object to identify the device.
To enable location, call requestLocationPermissions and requestLocationServices method. For Android 6.0 and above, calling this method will trigger a location permission popup that the user has to allow and startTracking the user location.
Step 5: Create MainActivity.java
Add Google Map SDK in MainActivity.java. Add Marker Image in centre of Google Map in main_activity.xml to get location co-ordinates.
Use GeoSpark's createGeofence, geofenceList and deleteGeofence method to manage geofence data like (Latitude, Longitude, ExpireTime and Radius) in GeoSpark server.
Make sure radius should be (50 -1000 meters) and set expiry time less than 24hrs.
Step 6: Add Notification Message
Add a Local Notification message to notify when user reaches the geofence area.
Step 7: Trigger Notification
Get the user location from GeoSparkReceiver and compare it with the already created geofence Location. If user location is inside geofence radius, trigger a local Notification.
Now your application for location triggered notifications is successfully built.
Ready to take the next steps?
Thank you for reading! If you're interested in seeing our product in action, click here to get in contact with our team. Or, if you're ready to get started, you can sign up here to start using our SDK and APIs today.