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
Update Maps documentation for .NET 11 features (#3212)
* Update Maps documentation for .NET 11 features
Document all new Maps APIs added in .NET 11 via the Maps epic (dotnet/maui#33787):
- Pin clustering (IsClusteringEnabled, ClusterClicked, ClusteringIdentifier)
- Custom pin icons (Pin.ImageSource)
- MoveToRegion animated overload and MapSpan.FromLocations
- Pin.ShowInfoWindow() and Pin.HideInfoWindow()
- MapLongClicked event
- MapElementClick event for Circle/Polygon/Polyline
- UserLocationChanged event and LastUserLocation property
- Map.MapStyle for custom JSON styling (Android)
- MapElement.IsVisible and MapElement.ZIndex
- XAML TypeConverters (LocationTypeConverter, MapSpanTypeConverter)
- Map.Region bindable property
All new content gated with >=net-maui-11.0 moniker ranges.
Closes#3208
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Remove undefined net-maui-11.0 moniker zones from map.md
The net-maui-11.0 moniker is not yet registered in the build system,
causing validation errors. Remove the zone markers while keeping all
.NET 11 content inline. Moniker zones can be re-added once the moniker
is defined.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Revert "Remove undefined net-maui-11.0 moniker zones from map.md"
This reverts commit 5c7f63e.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Theseproperties, withtheexceptionofthe `MapElements`, `Pins`, and `VisibleRegion` properties, arebackedby<xref:Microsoft.Maui.Controls.BindableProperty>objects, whichmeantheycanbetargetsofdatabindings.
169
178
170
179
The<xref:Microsoft.Maui.Controls.Maps.Map>classalsodefinesa `MapClicked` eventthat's fired when the map is tapped. The `MapClickedEventArgs` object that accompanies the event has a single property named `Location`, of type `Location`. When the event is fired, the `Location` property is set to the map location that was tapped. For information about the `Location` class, see [Location and distance](#location-and-distance).
@@ -277,6 +286,24 @@ The result is that when the map is displayed, it's centered on a specific locati
277
286
278
287
:::imagetype="content"source="media/map/map-region.png"alt-text="Screenshot of map control with specified location.":::
279
288
289
+
:::monikerrange=">=net-maui-11.0"
290
+
291
+
In .NET11, youcanusethe `Region` bindablepropertywithXAMLtypeconvertersforamoreconcisesyntax:
In .NET11, the `MapSpan` classalsoincludesa `FromLocations` methodthatcreatesa `MapSpan` thatencompassesallthespecifiedlocationswithappropriatepadding:
>Accessingtheuser's location requires location permissions to have been granted to the application. For more information, see [Platform configuration](#platform-configuration).
409
471
472
+
:::monikerrange=">=net-maui-11.0"
473
+
474
+
In .NET11, when `IsShowingUser` is `true`, themapprovidesadditionaluserlocationcapabilities:
475
+
476
+
-The `UserLocationChanged` eventfireswhenevertheuser's location is updated on the map. The `UserLocationChangedEventArgs` contains a `Location` property with the updated coordinates.
477
+
-The `LastUserLocation` propertyreturnsthemostrecentuserlocation, or `null` ifnolocationhasbeenreceivedyet.
// Access the last known user location at any time
492
+
Location?lastLocation=map.LastUserLocation;
493
+
```
494
+
495
+
:::moniker-end
496
+
410
497
#### Map clicks
411
498
412
499
The<xref:Microsoft.Maui.Controls.Maps.Map>classdefinesa `MapClicked` eventthat's fired when the map is tapped. The `MapClickedEventArgs` object that accompanies the event has a single property named `Location`, of type `Location`. When the event is fired, the `Location` property is set to the map location that was tapped. For information about the `Location` class, see [Location and distance](#location-and-distance).
@@ -433,6 +520,40 @@ Map map = new Map();
433
520
map.MapClicked+=OnMapClicked;
434
521
```
435
522
523
+
:::monikerrange=">=net-maui-11.0"
524
+
525
+
In .NET11, the<xref:Microsoft.Maui.Controls.Maps.Map>classdefinesadditionalinteractionevents:
526
+
527
+
##### Map long click
528
+
529
+
The `MapLongClicked` eventisfired when the user performs a long press/hold gesture on the map. Like `MapClicked`, the event provides the location of the long press through `MapClickedEventArgs`:
530
+
531
+
```csharp
532
+
map.MapLongClicked += (sender, args) =>
533
+
{
534
+
// Add a pin at the long-pressed location
535
+
map.Pins.Add(newPin
536
+
{
537
+
Label="Dropped Pin",
538
+
Location=args.Location
539
+
});
540
+
};
541
+
```
542
+
543
+
##### Map element click
544
+
545
+
The `MapElementClick` eventisfired when a user taps on a `Circle`, `Polygon`, or `Polyline` on the map. The `MapElementClickEventArgs` provides the tapped `MapElement`:
546
+
547
+
```csharp
548
+
map.MapElementClick += (sender, args) =>
549
+
{
550
+
MapElementclickedElement=args.MapElement;
551
+
System.Diagnostics.Debug.WriteLine($"Tapped a {clickedElement.GetType().Name}");
552
+
};
553
+
```
554
+
555
+
:::moniker-end
556
+
436
557
## Location and distance
437
558
438
559
The `Microsoft.Maui.Devices.Sensors` namespacecontainsa `Location` classthat's typically used when positioning a map and its pins. The `Microsoft.Maui.Maps` namespace contains a `Distance` struct that can optionally be used when positioning a map.
@@ -503,6 +624,13 @@ The `Pin` class has the following properties:
Thesepropertiesarebackedby<xref:Microsoft.Maui.Controls.BindableProperty>objects, whichmeansa `Pin` canbethetargetofdatabindings. Formoreinformationaboutdatabinding `Pin` objects, see [Displayapincollection](#display-a-pin-collection).
507
635
508
636
Inaddition, the `Pin` classdefines `MarkerClicked` and `InfoWindowClicked` events. The `MarkerClicked` eventisfired when a pin is tapped, and the `InfoWindowClicked` event is fired when the information window is tapped. The `PinClickedEventArgs` object that accompanies both events has a single `HideInfoWindow` property, of type `bool`.
The `ClusterClicked` eventisraised when a cluster marker is tapped. The `ClusterClickedEventArgs` provides the list of pins in the cluster, the location of the cluster, and a `Handled` property to suppress the default zoom behavior:
876
+
877
+
```csharp
878
+
map.ClusterClicked += (sender, args) =>
879
+
{
880
+
System.Diagnostics.Debug.WriteLine($"Cluster with {args.Pins.Count} pins tapped");
881
+
882
+
// Set Handled to true to prevent the default zoom-to-cluster behavior
>CustomJSONmapstylingisonlysupportedonAndroid. OniOS, MacCatalyst, andWindows, the `MapStyle` propertyhasnoeffect. AppleMapKitdoesnotsupportcustomJSONmapstyling.
1267
+
1268
+
:::moniker-end
1269
+
1003
1270
## Geocoding and geolocation
1004
1271
1005
1272
The `Geocoding` class, inthe `Microsoft.Maui.Devices.Sensors` namespace, canbeusedtogeocodeaplacemarktopositionalcoordinatesandreversegeocodecoordinatestoaplacemark. Formoreinformation, see [Geocoding](~/platform-integration/device/geocoding.md).
0 commit comments