Articles in this section
Category / Section

How to integrate .NET MAUI Maps with android native embedding application?

2 mins read

In this article, you will learn how to create a .NET MAUI Maps native embedded Android application following the step-by-step process explained below.

Step 1:
Create a .NET Android application and install the Syncfusion.Maui.Maps NuGet package using the nuget.org.

Step 2:
Add the <UseMaui>true</UseMaui> tag in your project file (.csproj) to enable .NET MAUI support.

[XAML]:

<PropertyGroup>
   <Nullable>enable</Nullable>
   <ImplicitUsings>enable</ImplicitUsings>
   <UseMaui>true</UseMaui>
</PropertyGroup>

Step 3:
Initialize .NET MAUI in the native app project by creating a MauiAppBuilder object and using the UseMauiEmbedding function. Then, use the Build() method on the MauiAppBuilder object to build a MauiApp object. Finally, create a MauiContext object from the MauiApp object to convert .NET MAUI controls to native types.

[C#]:

MauiContext? _mauiContext;
protected override void OnCreate(Bundle? savedInstanceState)
{
   base.OnCreate(savedInstanceState);
   MauiAppBuilder builder = MauiApp.CreateBuilder();
   builder.UseMauiEmbedding<Microsoft.Maui.Controls.Application>();
   builder.ConfigureSyncfusionCore();
   MauiApp mauiApp = builder.Build();
   _mauiContext = new MauiContext(mauiApp.Services, this);
}

Step 4:
Create a new instance for the SfMaps control, add a shape layer to it, and set the source of the map shapes using the ShapesSource property of the MapShapeLayer.

[C#]:

protected override void OnCreate(Bundle? savedInstanceState)
{
  ...
  SfMaps map = new SfMaps();
  MapShapeLayer layer = new MapShapeLayer();
  layer.ShapesSource = MapSource.FromUri(new Uri("https://cdn.syncfusion.com/maps/map-data/world-map.json"));
  map.Layer = layer;
  ...
}

Step 5:
Convert the SfMaps control to a platform-specific view for the .NET MAUI framework and set this view as the content view for the current Android activity.

[C#]:

protected override void OnCreate(Bundle? savedInstanceState)
{
  Android.Views.View view = map.ToPlatform(_mauiContext);

  // Set our view from the "main" layout resource
  SetContentView(view);
}

Download the complete sample from GitHub.

Output:

Map-Android-Native-Embedding.png

Conclusion:
I hope you enjoyed learning how to integrate Android native embedding for the .NET MAUI Maps (SfMaps).

You can refer to our .NET MAUI Maps feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI Maps documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Maps and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied