Add UserLocationChanged event and LastUserLocation property to Map#33799
Add UserLocationChanged event and LastUserLocation property to Map#33799jfversluis merged 4 commits intonet11.0from
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a public way to observe the Map control’s user-location updates (event + last-known location) when IsShowingUser is enabled, with iOS/Android handler wiring and sample/test coverage.
Changes:
- Introduces
Map.LastUserLocation,Map.UserLocationChanged, andUserLocationChangedEventArgsin Controls.Maps. - Extends the core
IMapcontract and wires platform callbacks on iOS (DidUpdateUserLocation) and Android (MyLocationChange). - Adds unit tests and a new sample gallery page demonstrating the feature.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Core/maps/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt | Declares new IMap members in netstandard API surface. |
| src/Core/maps/src/PublicAPI/net/PublicAPI.Unshipped.txt | Declares new IMap members in net API surface. |
| src/Core/maps/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt | Declares new IMap members in Windows API surface. |
| src/Core/maps/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt | Declares new IMap members in Tizen API surface. |
| src/Core/maps/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | Declares new IMap members in MacCatalyst API surface. |
| src/Core/maps/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt | Declares new IMap members in iOS API surface. |
| src/Core/maps/src/PublicAPI/net-android/PublicAPI.Unshipped.txt | Declares new IMap members in Android API surface. |
| src/Core/maps/src/Platform/iOS/MauiMKMapView.cs | Hooks iOS user-location updates and forwards them to the virtual view. |
| src/Core/maps/src/Handlers/Map/MapHandler.Android.cs | Hooks Android location change event and forwards updates to the virtual view. |
| src/Core/maps/src/Core/IMap.cs | Adds LastUserLocation and UserLocationUpdated to the core map interface. |
| src/Controls/tests/Core.UnitTests/MapTests.cs | Adds unit tests validating event firing and location storage behavior. |
| src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/UserLocationGallery.xaml.cs | Adds code-behind demonstrating UserLocationChanged and LastUserLocation. |
| src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/UserLocationGallery.xaml | Adds sample UI for displaying live user-location updates. |
| src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapsGallery.cs | Adds navigation entry for the new User Location sample page. |
| src/Controls/Maps/src/UserLocationChangedEventArgs.cs | Introduces new EventArgs type carrying the updated Location. |
| src/Controls/Maps/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt | Declares new Controls.Maps APIs (property/event/eventargs) in netstandard surface. |
| src/Controls/Maps/src/PublicAPI/net/PublicAPI.Unshipped.txt | Declares new Controls.Maps APIs (property/event/eventargs) in net surface. |
| src/Controls/Maps/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt | Declares new Controls.Maps APIs (property/event/eventargs) in Windows surface. |
| src/Controls/Maps/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt | Declares new Controls.Maps APIs (property/event/eventargs) in Tizen surface. |
| src/Controls/Maps/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | Declares new Controls.Maps APIs (property/event/eventargs) in MacCatalyst surface. |
| src/Controls/Maps/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt | Declares new Controls.Maps APIs (property/event/eventargs) in iOS surface. |
| src/Controls/Maps/src/PublicAPI/net-android/PublicAPI.Unshipped.txt | Declares new Controls.Maps APIs (property/event/eventargs) in Android surface. |
| src/Controls/Maps/src/Map.cs | Adds UserLocationChanged event and LastUserLocation property to Map. |
| src/Controls/Maps/src/HandlerImpl/Map.Impl.cs | Implements the new IMap members and raises the new event. |
|
/rebase |
cdc2f35 to
bc5011c
Compare
a622204 to
c961038
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Independent Code ReviewSummary: Adds ✅ What Looks Good
🔴 Issues1. 2. Android 3. No Windows implementation 4. High-frequency event with no throttling 🟡 Nits
|
|
Thanks for the detailed review @kubaflo! 1. LastUserLocation is not a BindableProperty 2. Android MyLocationChange is deprecated 3. No Windows implementation 4. High-frequency event with no throttling 5. Location.Equals comparison |
🔍 Round 2 Review — PR #33799 (UserLocationChanged)Updated with author response analysis ✅ What Looks Good
|
|
/azp run maui-pr |
|
Azure Pipelines successfully started running 1 pipeline(s). |
📋 Round 3 — PR #33799 (UserLocationChanged) — Final RecommendationNo outstanding issues. All Round 2 concerns were satisfactorily addressed. Note on CI: This PR has a Recommendation: Re-run |
c961038 to
5262a29
Compare
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 33799Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 33799" |
5262a29 to
3f16dd0
Compare
- Add LastUserLocation property to IMap interface and Map control - Add UserLocationChanged event fired when user location updates - Add UserLocationChangedEventArgs class - iOS: Subscribe to MKMapView.DidUpdateUserLocation - Android: Subscribe to GoogleMap.MyLocationChange - Add 7 unit tests for UserLocationChanged functionality - Add UserLocationGallery sample page Addresses #14700
- Add PropertyChanging/PropertyChanged notifications when LastUserLocation changes - Skip update if location hasn't changed (mirror VisibleRegion pattern) - Clarify XML docs about when UserLocationChanged fires
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Make event handler parameters nullable (object?) - Use fully-qualified Location type to avoid XAML sourcegen conflict Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3f16dd0 to
62b01f2
Compare
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
This PR adds the ability to receive user location updates from the Map control when
IsShowingUseris enabled.New Public API
Map.LastUserLocation- Read-only property that returns the most recent user location, or null if not yet availableMap.UserLocationChanged- Event fired whenever the user's location is updated on the mapUserLocationChangedEventArgs- Event arguments containing theLocationpropertyPlatform Implementation
MKMapView.DidUpdateUserLocationdelegate methodGoogleMap.MyLocationChangeeventUsage
Changes
LastUserLocationproperty andUserLocationUpdatedmethod toIMapinterfaceLastUserLocationproperty andUserLocationChangedevent toMapclassUserLocationChangedEventArgsclassDidUpdateUserLocationinMauiMKMapViewMyLocationChangeinMapHandler.AndroidUserLocationGallerysample pageIssues Fixed
Addresses #14700
Part of Maps Epic
Part of #33787 (Epic: Maps Control Improvements for .NET 11)