You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/platform-integration/device/geolocation.md
+63
Original file line number
Diff line number
Diff line change
@@ -138,6 +138,69 @@ Not all location values may be available, depending on the device. For example,
138
138
> [!WARNING]
139
139
> <xref:Microsoft.Maui.Devices.Sensors.IGeolocation.GetLocationAsync%2A> can return `null` in some scenarios. This indicates that the underlying platform is unable to obtain the current location.
140
140
141
+
::: moniker range=">=net-maui-8.0"
142
+
143
+
## Listen for location changes
144
+
145
+
In addition to querying the device for the current location, you can listen for location changes while an app is in the foreground.
146
+
147
+
To check to see if the app is currently listening for location changes, there's a `IsListeningForeground` property you can query. Once you're ready to start listening for location changes you should call the `StartListeningForegroundAsync` method. This method starts listening for location updates and raises the `LocationChanged` event when the location changes, provided that the app is in the foreground. The `GeolocationLocationChangedEventArgs` object that accompanies this event has a `Location` property, of type <xref:Microsoft.Maui.Devices.Sensors.Location>, that represents the new location that's been detected.
148
+
149
+
> [!NOTE]
150
+
> When necessary, the Geolocation API prompts the user for permissions.
151
+
152
+
The following code example demonstrates how to listen for a location change, and how to process the changed location:
Error handling can be implemented by registering an event handler for the `ListeningFailed` event. The `GeolocationListeningFailedEventArgs` object that accompanies this event has an `Error` property, of type `GeolocationError`, that indicates why listening failed. When the `ListeningFailed` event is raised, listening for further location changes stops and no further `LocationChanged` events are raised.
180
+
181
+
To stop listening for location changes, call the `StopListeningForeground` method:
Copy file name to clipboardexpand all lines: docs/whats-new/dotnet-8.md
+1
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,7 @@ For information about what's new in .NET 8, see [What's new in .NET 8](/dotnet/c
44
44
- Shell navigation gains a `GoToAsync` overload that enables you to pass single use navigation data, that's cleared after navigation has occurred, as a `ShellNavigationQueryParameters` object. For more information, see [Pass single use object-based navigation data](~/fundamentals/shell/navigation.md#pass-single-use-object-based-navigation-data).
45
45
- Window management can be decoupled from the `App` class. For more information, see [Decouple window management from the App class](~/fundamentals/windows.md#decouple-window-management-from-the-app-class).
46
46
- Menu bar items and context menu items can be invoked through keyboard shortcuts known as keyboard accelerators. For more information, see [Keyboard accelerators](~/user-interface/keyboard-accelerators.md).
47
+
- The <xref:Microsoft.Maui.Devices.Sensors.Geolocation> class can listen for location changes when app's are in the foreground. For more information, see [Listen for location changes](~/platform-integration/device/geolocation.md#listen-for-location-changes).
47
48
48
49
The following types or members have been deprecated:
0 commit comments