Location Tracking

Location Tracking

In many cases it’s important to log the location of a user and associate that location with other events. The mParticle SDK allows you to include detailed location information with all of your events.

There are two ways to approach location tracking:

  1. You can call the enableLocationTracking method and let the mParticle SDK collect and update location information for you. Remember to call disableLocationTracking when you no longer need to track location
  2. Set the location property directly. In this case you are responsible for maintaining location updated and setting it to nil/null when no longer needed
// Specify a provider and minimum time (milliseconds) and minimum distance (meters) between location updates.
MParticle.getInstance().enableLocationTracking(LocationManager.NETWORK_PROVIDER, 30*1000, 100);

//alternatively, an application can manage it's own location updates
//and manually set an android.location.Location object
MParticle.getInstance().setLocation(someLocation);

See the Android developer guidelines for more info on available providers and the permissions that are required.