I'm trying to get maps to work on .net MAUI and found this blog post (linked to from the official MAUI blog). https://www.cayas.de/blog/dotnet-maui-custom-map-handler I've downloaded the repo linked at the end of the blog but I can't get it to run.
In the blog post the MapHandler code looks like this:
public static IPropertyMapper<IMap, MapHandler> MapMapper = new PropertyMapper<IMap, MapHandler>(ViewMapper)
{ };
But in the repo it looks like this:
public static IPropertyMapper<MapView, MapHandler> MapMapper = new PropertyMapper<MapView, MapHandler>(ViewMapper)
{ };
Neither of which work for me, as I get the error (at runtime) below.
The type 'MapControlDemo.Handlers.MapHandler' cannot be used as type parameter 'TViewHandler' in the generic type or method 'PropertyMapper<TVirtualView, TViewHandler>'. There is no implicit reference conversion from 'MapControlDemo.Handlers.MapHandler' to 'Microsoft.Maui.IElementHandler'
Confusingly there are another couple of errors that shouldn't be errors??
Any ideas? I contacted the author and he suggested it could be my maui version as it works for him, but I'm on the latest.
Perhaps the author was building on a Mac.
I've confirmed that an attempt to build on Windows results in a build error. VS Version 17.3.0 Preview 1.1
The error I got was
Error CS0311 The type 'MapControlDemo.Handlers.MapHandler' cannot be used
as type parameter 'TViewHandler'
in the generic type or method 'IPropertyMapper<TVirtualView, TViewHandler>'.
There is no implicit reference conversion from
'MapControlDemo.Handlers.MapHandler' to
'Microsoft.Maui.IElementHandler'.
MapControlDemo (net6.0-android) C:\...\maui-maps\Handlers\MapHandler.cs 6
HOWEVER, I was able to RUN on Android - by selected an Android emulator as target (so using net6.0-android
) and pressing F5 - therefore that error is misleading.
Given that this is only implemented on iOS and Android, I recommend editing .csproj
to REMOVE Windows
platform. I also removed MacCatalyst (maybe that would work but I was going for simplest test):
Change:
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
To:
<TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>
Then I was able to build.
NOTE: Without adding a Google Maps ID, when ran on Android, the result was an empty map.
tl;dr Easiest way to test is on a Mac, targetting iOS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With