platform specific maps

Eduardo Gomez Romero 845 Reputation points
2024-08-29T01:54:20.8366667+00:00

I already install Microsoft.Maui.Controls.Maps NuGet package and

CommunityToolkit.Maui.Maps

and register my Api key and everything work for Android and for Windows, and configure mauiProgram

    public static MauiApp CreateMauiApp() {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseMauiCommunityToolkit()
            .ConfigureSyncfusionCore()
#if ANDROID || IOS
            .UseMauiMaps()
#elif WINDOWS
             .UseMauiCommunityToolkitMaps("AlKrbMWDZLkrL510ErB0LyjdmGrPsKiDayOH6V8tSBmlJYdQufZFtTnY_DEZG2xf")
#endif
            .ConfigureFonts(fonts => {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });


but I don't know how to differentiate in xaml

<ContentPage
    x:Class="METROWIND.Views.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:behaviors="clr-namespace:METROWIND.Behavior"
    xmlns:maps="http://schemas.microsoft.com/dotnet/2021/maui/maps"
    xmlns:mapsWin="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps"
    xmlns:model="clr-namespace:METROWIND.Models"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    xmlns:vm="clr-namespace:METROWIND.ViewModels"
    x:DataType="vm:MainViewModel">

    <maps:Map x:Name="map" />

this work forAndroid, but how do i put the windows only map

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,594 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 44,011 Reputation points Microsoft Vendor
    2024-08-29T06:24:25.0033333+00:00

    Hello,

    this work forAndroid, but how do i put the windows only map

    ·CommunityToolkit.Maui.Maps· is a supplement to using the Map control on the Windows platform. Therefore, on Windows, you do not need to distinguish it from other platforms, the application will automatically switch the API used by the map. The reason why your map cannot be displayed as expected on Windows is due to the referenced namespace.

    When using this package, you do not need to reference the map control in xaml with xmlns:maps="http://schemas.microsoft.com/dotnet/2021/maui/maps", but you need to use xmlns:maps="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps".

    After declaring the namespace in the above way, you can directly use <maps:Map x:Name="map" />, and Maui will automatically switch to Bing maps when running on Windows.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.