---
title: Listen to location
description: How to listen to your user's location
---

# Listen to Location

To listen to the location of the user, you can simply use

```dart
Stream<LocationData> get onLocationChanged
```

The stream uses the global settings for location tracking.
You can change them with [`changeSettings`](/features/settings).

If you change settings while listening to the location, the stream will use the new settings without being closed (you can only have one set of global settings active at the same time).

Don't forget to **cancel the stream** when you don't need it anymore. Otherwise the location will keep being tracked.

To receive location updates while the app is in the background, enable background mode with `enableBackgroundMode(enable: true)` first.
On Android, background location triggers a notification that you can control with [`changeNotificationOptions`](/features/notification).

By default, `enableBackgroundMode` also requests the `ACCESS_BACKGROUND_LOCATION`
("Allow all the time") permission on Android if it hasn't been granted yet. A
foreground service with the location type actually retains location access
while backgrounded *without* that permission at all — it's only required for
location access outside of an active foreground service (e.g. a periodic
background fetch with no visible notification). If you only need updates
while your foreground service notification is showing, pass
`requireBackgroundPermission: false` to skip that stricter prompt and start
the foreground service directly on just the regular (fine/coarse) location
permission:

```dart
await location.enableBackgroundMode(
  enable: true,
  requireBackgroundPermission: false,
);
```

Android only; ignored on other platforms.

## Examples

### Listening to location

```dart
final location = Location();
final subscription = location.onLocationChanged
    .listen((LocationData currentLocation) {
        print('Location: ${currentLocation.latitude}, ${currentLocation.longitude}');
    });

// ...

subscription.cancel();
```

### Listening to location in the background

The notification will only appear on Android

```dart
final location = Location();
await location.enableBackgroundMode(enable: true);
final subscription = location.onLocationChanged
    .listen((LocationData currentLocation) async {
        await location.changeNotificationOptions(
            subtitle:
                'Location: ${currentLocation.latitude}, ${currentLocation.longitude}',
            onTapBringToFront: true,
        );
    });

// ...

subscription.cancel();
```
