Reputation: 532
I'm playing around with .Net Maui. I'd like to add a map to my demo app. Unfortunately it seems that the map control has not been migrated yet. Also it seems that the promised implementation of the control has been removed from the roadmap for RC.
Also existing projects like this one: https://github.com/amay077/Xamarin.Forms.GoogleMaps doesn't support .Net Maui...
Does anybody already include a map to a .Net Maui project and could give me some a hint?
Thx!
Upvotes: 13
Views: 11329
Reputation: 85
From .net7.0 you can use Map controls.
More info about this you can find here.
I created last week my own topic about it for databinding. You can find it here.
Upvotes: 1
Reputation: 1439
With .net 7.0 there has been added the control Microsoft.Maui.Controls.Maps
Documentation: Map
Simple demo Maui app: MapDemo
Upvotes: 2
Reputation: 111
i have ported Xamarin.Forms.GoogleMaps to .NET MAUI. Feel free to contact me if u have any issues: https://www.nuget.org/packages/Onion.Maui.GoogleMaps/
Upvotes: 1
Reputation: 2879
To use Google or Apple Maps in .NET MAUI, while it is not yet in the Framework , make use of your own handler. You can find a detailed blog post on our website.
But in general, you have to do the following steps:
public class MapView : View, IMapView
{ }
This is the control you use inside your ContentPage.
To render your view, MAUI needs a platform-independent entry point.
partial class MapHandler
{
public static IPropertyMapper<MapView, MapHandler> MapMapper = new PropertyMapper<MapView, MapHandler>(ViewMapper)
{ };
public MapHandler() : base(MapMapper)
{ }
}
That needs to be registered in your MauiProgram.cs
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(MapHandlerDemo.Maps.Map),typeof(MapHandler));
})
A handler tells MAUI how to render your control. So you need a handler for each platform you want to support. The iOS handler is, in comparison to Android, simpler and shorter to implement.
public partial class MapHandler : ViewHandler<MapView, MKMapView>
{
public MapHandler(IPropertyMapper mapper, CommandMapper commandMapper = null) : base(mapper, commandMapper)
{ }
protected override MKMapView CreatePlatformView()
{
return new MKMapView(CoreGraphics.CGRect.Empty);
}
protected override void ConnectHandler(MKMapView PlatformView)
{ }
protected override void DisconnectHandler(MKMapView PlatformView)
{
// Clean-up the native view to reduce memory leaks and memory usage
if (PlatformView.Delegate != null)
{
PlatformView.Delegate.Dispose();
PlatformView.Delegate = null;
}
PlatformView.RemoveFromSuperview();
}
}
Next step would be to implement your Android handler.
Upvotes: 7
Reputation: 27
Try the GoogleApi package by Michael Vivet on NuGet. It is compatible with Net5. I have downloaded the source and added Net6 to the dll, it works perfectly.
Upvotes: 1
Reputation: 155
I also missing it. In an earlier roadmap of the MAUI team it was announced for February/2022 and MAUI Version 12, but meanwhile we have end of March and MAUI 14, but no progress in the map control. But Xamarin, the predecessor, still have it. Btw. that prevents me to move to MAUI.
Upvotes: 3
Reputation: 1241
Try like this please:
<WebView Source="https://embed.windy.com" />
Upvotes: -2