final LocationProvider _location_provider = LocationProvider(YOUR_API_KEY);
_location_provider.synchronizeData();
_location_provider.start();
Example to receive the synchronization success callback
_location_provider.setDidSynchronizationSuccessCallbackHandler(LocationMonitor.didSynchronizationSuccess);
Example to receive the location changed callback
_location_provider.setDidLocationChangeCallbackHandler(LocationMonitor.locationCallback);
static void locationCallback(Location? location) {
// We use isolate ports to communicate between the main isolate and spawned
// isolates since they do not share memory. The port lookup will return
// null if the UI isolate has explicitly removed the mapping on shutdown.
final SendPort? uiSendPort =
IsolateNameServer.lookupPortByName(kLocationPluginPortName);
uiSendPort?.send(location?.toJson());
}
static void didSynchronizationSuccess() { print('Synchronization successful!'); }