Netmera Location Service

NetmeraLocationService (previously NetmeraGeofenceService) is a service that enables developers tracking location for NetmeraPush service. If you want to send locational push notifications and if you use this service, you don’t need to track device locations anymore. This service automatically updates device location. It allows you to create location based push notification campaigns with time and distance intervals. When your users get closer to specific location, you can send automated push messages to them in certain time interval.

Using the following steps, you can easily add Location Tracking feature to your apps.

Step 1 Location Service uses Google Play Services SDK. You need to add Google Play Services library project to your project. Here is the link about how to set up development environment and project with Google Play Services SDK.

After installation and creating a project with Google Play Services SDK, you need to add location permissions to your Manifest.xml file. There are 2 different types of permission for this. First one is ACCESS_COARSE_LOCATION. This permission gets coarse location. It allows you to access approximate location derived from network location sources such as cell towers and Wi-Fi. The other is ACCESS_FINE_LOCATION. It allows your app to access precise location from location sources such as GPS, cell towers, and Wi-Fi. If you don’t need exact location of user and if your app is not a map/navigation app, we advise you to use coarse location over fine. For battery life optimization, coarse is also better than fine since it does not use GPS.

To start Netmera Location Service, you need to add the following line to your Manifest.xml file.

<service android:name="" />

When you run the project, this service will automatically start collecting location data and send it to Netmera if you enabled location tracking in file or NetmeraProperties Object’s builder which could be used in Netmera.init function. Otherwise, you need to set your default values and call necessary methods mentioned below. Default parameters are as follows:

Interval distance: 150 meters

Interval time: 15 minutes

Fastest interval: 10 minutes


These are optimized values for location service. If you want to customize values, you need to create your own NetmeraLocationSettings object and start Location Service with this NetmeraLocationSettings object.

Step 2

Before starting NetmeraLocationService, you should create a NetmeraLocationSettings object. You can change its default parameters as you wish. If you don’t set optional values, default values will be used.

Let’s clarify the terms that we will use them to customize Location Service.

The fastest interval parameter sets the fastest interval for location updates, in milliseconds. Please read the documentation for details on Google Play Services Reference document. Click here to open it.

The interval distance parameter (intervalMeters) can be used to control the frequency of location updates. If it is greater than 0, then the location provider will send an update when the location has changed by at least interval distance meters, OR at least the interval time (intervalSeconds) seconds have passed. Location Service will read the location and send location updates to Netmera to check if there is any event/trigger/geofence push related to this location. For more detail about this interval time parameter, please click here. For interval distance parameter, click here.

The other important parameter is priority.

There are 4 types of priority. PRIORITY_BALANCED_POWER_ACCURACY, PRIORITY_HIGH_ACCURACY, PRIORITY_LOW_POWER, PRIORITY_NO_POWER. Please follow the link to get more information about them. Click here.

An example usage of the NetmeraLocationSettings class may be like this.

NetmeraLocationSettings locationSettings = new NetmeraLocationSettings();
locationSettings.setIntervalSeconds(15 * 60).setIntervalMeters(200)
.setFastestInterval(10 * 60 * 1000).setPriority(NetmeraLocationSettings.PRIORITY_LOW_POWER);
NetmeraLocationService.init(locationSettings, getApplicationContext());

*In this example setIntervalSeconds parameter equals to 15 minutes, intervalMeters parameter is equal to 200 meters and setFastestInterval parameter(in miliseconds) is equal to 10 minutes. You can change values based on your requirements. It is just an example. If you need more frequent location updates, you can change these values but please keep in mind that using so small intervals will decrease phone’s battery level more.

After creating NetmeraLocationSettings object, you should initialize NetmeraLocationService by passing NetmeraLocationSettings object and context. To start NetmeraLocationService you should call startLocationService() method.

NetmeraLocationService.init(locationSettings, getApplicationContext());

If you want to stop NetmeraLocationService, you should call stopLocationService() method on NetmeraLocationService class. After calling this method, Netmera will not receive location updates anymore.


March 31, 2015 / parag

Recent Blog Posts
User Tagging and CRM Segmentation
Retargeting: how to make the best of your past mobile campaigns