Monitoramento de localização
Saiba como rastrear o local por meio do Braze SDK.
Logging the current location
Even if continuous tracking is disabled, you can manually log the user’s current location using the setLastKnownLocation()
method.
1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
@Override
public void onSuccess(BrazeUser brazeUser) {
brazeUser.setLastKnownLocation(LATITUDE_DOUBLE_VALUE, LONGITUDE_DOUBLE_VALUE, ALTITUDE_DOUBLE_VALUE, ACCURACY_DOUBLE_VALUE);
}
}
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
brazeUser.setLastKnownLocation(LATITUDE_DOUBLE_VALUE, LONGITUDE_DOUBLE_VALUE, ALTITUDE_DOUBLE_VALUE, ACCURACY_DOUBLE_VALUE)
}
Continuously tracking the location
Starting with Android Marshmallow, you must prompt your users to explicitly opt-in to location tracking. Once they do, Braze can start tracking their location at the beginning of the next session. This is unlike earlier versions of Android, where only declaring location permissions in your AndroidManifest.xml
was required.
To continuously track a user’s location, you’ll need to declare your app’s intent to collect location data by adding at least one of the following permissions to your AndroidManifest.xml
file.
Permission | Description |
---|---|
ACCESS_COARSE_LOCATION |
Uses the most battery-efficient, non-GPS provider (such as a home network). Typically, this is sufficient for most location-data needs. Under the runtime permissions model, granting location permission implicitly authorizes the collection of fine location data. |
ACCESS_FINE_LOCATION |
Includes GPS data for more precise location. Under the runtime permissions model, granting location permission also covers fine location access. |
Your AndroidManifest.xml
should be similar to the following:
1
2
3
4
5
6
7
8
<manifest ... >
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application ... >
...
</application>
</manifest>
Disabling continuous tracking
You can disable continuous tracking at compile time or runtime.
To disable continuous location tracking at compile time, set com_braze_enable_location_collection
to false
in braze.xml
:
1
<bool name="com_braze_enable_location_collection">false</bool>
To selectively disable continuous location tracking at runtime, use BrazeConfig
:
1
2
3
4
BrazeConfig brazeConfig = new BrazeConfig.Builder()
.setIsLocationCollectionEnabled(false)
.build();
Braze.configure(this, brazeConfig);
1
2
3
4
val brazeConfig = BrazeConfig.Builder()
.setIsLocationCollectionEnabled(false)
.build()
Braze.configure(this, brazeConfig)
guide/swift/analytics/tracking_location.md developer_ %}
guide/web/analytics/tracking_location.md developer_ %}