语言

AppHostBuilderExtensions.UseMauiMaps(MauiAppBuilder) 方法

定义

配置 MauiAppBuilder 以添加对 Map 控件的支持。

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Maui::Hosting::MauiAppBuilder ^ UseMauiMaps(Microsoft::Maui::Hosting::MauiAppBuilder ^ builder);
public static Microsoft.Maui.Hosting.MauiAppBuilder UseMauiMaps(this Microsoft.Maui.Hosting.MauiAppBuilder builder);
static member UseMauiMaps : Microsoft.Maui.Hosting.MauiAppBuilder -> Microsoft.Maui.Hosting.MauiAppBuilder
<Extension()>
Public Function UseMauiMaps (builder As MauiAppBuilder) As MauiAppBuilder

参数

builder
MauiAppBuilder

要 MauiAppBuilder 配置的。

例外

由于Windows当前未实现地图控件,因此在Windows引发。

注解

Windows(Azure Maps):使用ConfigureEssentials以下命令设置Azure Maps订阅密钥:

builder.ConfigureEssentials(essentials => essentials.UseMapServiceToken("YOUR_AZURE_MAPS_KEY"));

从Azure 门户获取密钥: https://portal.azure.com → Azure Maps帐户→身份验证

Windows功能(通过 Azure Maps JS API):Windows实现使用由 Azure Maps 支持的 WinUI 3 MapControl。 通过控件的内部 WebView2 访问Azure Maps JavaScript API来实现以下功能:

  • MoveToRegion: 通过 map.setCamera().
  • MapType: 街道/卫星/混合通过 map.setStyle()。
  • IsTrafficEnabled: 流量和事件通过 map.setTraffic()。
  • IsScrollEnabled/IsZoomEnabled: 通过 map.setUserInteraction(). 独立控制。
  • 固定:通过 MapIcon .MapElementsLayer

Windows平台限制:

  • 用户位置: 不内置;需要手动地理位置 API 集成。
  • 形状: 不支持折线、多边形和圆圈(MapElementsLayer 仅支持 MapIcon)。
  • 固定标签:MapIcon 不支持标签或信息窗口。
  • Map.Clicked (背景): 仅 MapElement 单击触发事件,而不是空地图区域单击。
有关详细的平台信息,请参阅 MapHandler 文档。

适用于