Receiving location events

In plugin version 3.3.0 for iOS and 3.8.0 for Android we introduced support for receiving location events. Every time the plugin detects the location of the device, it calls a hook you can define. A use-case for this functionality is localizing content based on device location in a battery-efficient way.

The frequency of calls to this hook differs on multiple variables and may change between plugin version updates. For example, the plugin requests the location more frequently when the phone is connected to a charger or when the app is in the foreground.

Whenever the plugin detects a new location, our plugin sends out an intent to which you can listen to with a broadcast receiver. When implementing, make sure to include it in the manifest, for example:

<receiver android:name=".NewLocationReceiver" android:exported="false">
        <action android:name="${applicationId}.plot.NewLocation" />
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;

public class NewLocationReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        Location location = intent.getParcelableExtra("location");

        //store or do something with the location