diff --git a/src/Controls/Maps/README.md b/src/Controls/Maps/README.md new file mode 100644 index 000000000000..4b591f932369 --- /dev/null +++ b/src/Controls/Maps/README.md @@ -0,0 +1,177 @@ +# Microsoft.Maui.Controls.Maps + +`Microsoft.Maui.Controls.Maps` brings an easy-to-use map control to .NET MAUI apps so you can display maps, drop pins, draw shapes, and react to user interactions on Android and iOS from one shared codebase. (Windows implementation is not available yet.) + +## πŸš€ Get started + +1. **Install the package** + ```bash + dotnet add package Microsoft.Maui.Controls.Maps + ``` +2. **Enable Maps in `MauiProgram.cs`** + ```csharp + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .UseMauiMaps(); // registers map handlers + ``` +3. **Add platform credentials** + - **Android**: Add your Google Maps API key to `Platforms/Android/AndroidManifest.xml` + ```xml + + + + ``` + - **iOS**: No additional keys required for the built-in map provider. + - **Windows**: The Maps control is currently not implemented on Windows. For updates, see [this tracking link](https://aka.ms/maui-maps-no-windows). + +4. **Place a map in your page** + ```xml + + + + + + + + 47.6205 + -122.3493 + + + + + + + + ``` + +## 🧭 Features at a glance + +- **Pins**: Labels, addresses, pin types, custom images, and tap handling via `PinClicked`. +- **Shapes**: Draw **polygons**, **polylines**, and **circles** to outline areas or routes. +- **Map interactions**: Handle `MapClicked`, move the camera/region, and programmatically add or remove map elements at runtime. +- **Map display**: Switch map types (e.g., Street, Satellite, Hybrid) and control gesture support (scroll, zoom, rotate). +- **User location**: Show the user’s current location with `IsShowingUser` (platform location permission required). + +### Samples: pins and shapes + +```xml + + + + + + + 47.6424 + -122.3219 + + + + + + + + + + + + 47.642 + -122.323 + + + + + 47.643 + -122.326 + + + + + 47.640 + -122.327 + + + + + + + + + + 47.639 + -122.330 + + + + + 47.640 + -122.335 + + + + + + + + + + 47.641 + -122.329 + + + + + + + 200 + + + + + + +``` + +### Samples: interactions and map modes + +```csharp +// In code-behind +void OnMapClicked(object sender, MapClickedEventArgs e) +{ + // Drop a pin where the user tapped + var map = (Map)sender; + map.Pins.Add(new Pin + { + Label = "Dropped pin", + Type = PinType.Place, + Location = e.Location + }); + + // Move/zoom to the tapped location + map.MoveToRegion(MapSpan.FromCenterAndRadius(e.Location, Distance.FromMeters(500))); +} + +// Toggle map display mode +void ToggleMapType(Map map) => + map.MapType = map.MapType == MapType.Street ? MapType.Satellite : MapType.Street; + +// Common runtime toggles +void EnableLocationAndTraffic(Map map) +{ + map.IsShowingUser = true; // requires location permission on the device + map.IsTrafficEnabled = true; // show live traffic where supported +} +``` + +## πŸ“š Learn more + +- [.NET MAUI Map control docs](https://learn.microsoft.com/dotnet/maui/user-interface/controls/map) – capabilities, events, and platform guidance +- [.NET MAUI documentation](https://learn.microsoft.com/dotnet/maui/) – build and ship cross-platform apps diff --git a/src/Controls/Maps/src/Controls.Maps.csproj b/src/Controls/Maps/src/Controls.Maps.csproj index bfaae807eca3..db61d6819577 100644 --- a/src/Controls/Maps/src/Controls.Maps.csproj +++ b/src/Controls/Maps/src/Controls.Maps.csproj @@ -25,6 +25,7 @@ Microsoft.Maui.Controls.Maps $(DefaultPackageTags);maps;mapping Maps and mapping support for .NET Multi-platform App UI (.NET MAUI) apps. + README.md @@ -32,9 +33,12 @@ + + + - \ No newline at end of file +