Easily Visualize Online Maps in Your .NET MAUI Apps | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (201)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (63)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (80)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (894)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (62)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (37)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (499)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (380)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (321)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Easily Visualize Online Maps in Your .NET MAUI Apps

Easily Visualize Online Maps in Your .NET MAUI Apps

Syncfusion .NET MAUI Maps is a powerful data visualization control that displays statistical information for a geographical area. Its rich feature set includes selection, tooltips, legends, markers, bubbles, color mapping, and more. The shape layer renders geographical areas from GeoJSON data.

With tile-layer rendering support, we can load map tiles or images from web map tile services (WMTS) such as OpenStreetMap, Bing Maps, Google Maps, and TomTom.

In this blog, we will see how to visualize online maps with the title layer and how to enable markers, zooming, and panning features.

Tile layer in .NET MAUI Maps

The tile layer in .NET MAUI Maps is a collection of small images (tiles) that are combined to display a map in a mobile or desktop app. Each tile represents a small part of the overall map, and by combining multiple tiles a complete map can be displayed.

Tile layers are typically used to display maps from online mapping services such as OpenStreetMap, Bing Maps, Google Maps, and TomTom. This approach reduces the amount of data that needs to be loaded and the processing power required to display the map.

You can use this tile layer to zoom in on a specific region by pinching and panning the map to see what’s nearby.

Tile Layer Support in Syncfusion .NET MAUI Maps Control
Tile Layer Support in Syncfusion .NET MAUI Maps Control

Note: For more details, refer to how to configure and create an app with .NET MAUI Maps control.

Visualizing online map services in .NET MAUI Maps

Let’s see how to add and visualize various online map services using the Syncfusion .NET MAUI Maps control with the help of the tile layer!

Adding an OpenStreetMap

One of the most popular web map tile services is OpenStreetMap (OSM). It is a free and open-source map of the world created and maintained by a community of volunteers. If you are looking for a cost-effective map tile provider, then OpenStreetMap will work.

The map data is available to anyone under the Open Database License and can be used for many purposes, from creating maps to using the data for scientific research. It uses a standard set of web mapping protocols to deliver map tiles, such as the Web Map Service (WMS) and the Web Map Tile Service (WMTS).

Disclaimer: OpenStreetMap can be used for free. However, we recommend you check the licensing terms on its official website.

We need to add the OpenStreetMap to the MapTileLayer in the Layer property of .NET MAUI Maps.

Refer to the following code example.

<maps:SfMaps>
   <maps:SfMaps.Layer>
      <maps:MapTileLayer UrlTemplate="https://tile.openstreetmap.org/{z}/{x}/{y}.png" />
   </maps:SfMaps.Layer>
</maps:SfMaps>
Visualizing OpenStreetMap Using .NET MAUI Maps
Visualizing OpenStreetMap Using .NET MAUI Maps

How to set the URL template

The UrlTemplate property accepts the URL in WMTS format. This URL might vary slightly depending on providers. The formats can be:

  • https://exampleprovider/{z}/{x}/{y}.png
  • https://exampleprovider/z={z}/x={x}/y={y}.png
  • https://exampleprovider/z={z}/x={x}/y={y}.png?key=subscription_key

Here, {z} represents the zoom level, and {x} and {y} represent the tile’s x- and y-coordinates, respectively.

We will replace {z}, {x}, and {y} internally based on the zoom level and the tile position.

A subscription key may be needed for some of the providers, like Bing Maps and TomTom. Include it in the UrlTemplate.

Note: The format may vary among map providers. You can check the exact URL format needed for the providers on their official websites.

Adding Bing Maps

Another popular web map tile service is Bing Maps. It is a paid mapping service provided by Microsoft that offers a wide range of features, including aerial and street maps, 3D maps, and the ability to create custom maps with your own data. It uses standard web mapping protocols to deliver map tiles, such as WMS and WMTS.

How to set the URL template

Adding Bing Maps to the MapTileLayer is the same as adding OpenStreetMap except for the way we set the UrlTemplate property.

For Bing Maps, an additional step is required. We have to add the GetBingUrl method that returns the URL in the required form. You can use the URL returned from this method and set it to the UrlTemplate property.

A subscription key is needed for Bing Maps. We should add it to the UrlTemplate property.

Bing Maps also supports map types such as Road, Aerial, and AerialWithLabelsOnDemand. These types should also be added in the UrlTemplate itself.

Other than these differences, everything is the same for all the tile providers. Refer to the following code example.

XAML

<maps:SfMaps>
  <maps:SfMaps.Layer>
    <maps:MapTileLayer x:Name="tileLayer" />
  </maps:SfMaps.Layer>
</maps:SfMaps>

C#

public MainPage()
{
   InitializeComponent();
   this.GenerateBingUrl();
}
private async void GenerateBingUrl()
{
   tileLayer.UrlTemplate = await MapTileLayer.GetBingUrl("https://dev.virtualearth.net/REST/V1/Imagery/Metadata/RoadOnDemand?output=json&uriScheme=https&include=ImageryProviders&key=your_subscription_key");
}
Visualizing Bing Maps Using .NET MAUI Maps Control
Visualizing Bing Maps Using .NET MAUI Maps Control

Other tile providers

In addition to OpenStreetMap and Bing Maps, it is possible to add other tile providers, such as Google Maps and TomTom, which follow the WMTS format. For example, tiles from TomTom can be added as shown in the following code.

Note: You must append the subscription key at the end of the URL.

<maps:SfMaps>
 <maps:SfMaps.Layer>
  <maps:MapTileLayer UrlTemplate="https://api.tomtom.com/map/1/tile/basic/main/{z}/{x}/{y}.png?key=your_subscription_key" />
 </maps:SfMaps.Layer>
</maps:SfMaps>
Visualizing TomTom Map Using .NET MAUI Maps Control
Visualizing TomTom Map Using .NET MAUI Maps Control

Note: For more details, refer to the title layer in the .NET MAUI Maps documentation.

Enabling other data visualization features in .NET MAUI Maps

Now let’s see how to enable markers, zooming, and panning features in the Syncfusion .NET MAUI Maps control to effectively visualize online maps services in it.

Zooming and panning

You can enable zooming and panning on the map by using the ZoomPanBehavior property of the MapTileLayer. You can zoom in on the tile layer for a closer look at a specific region by:

  • Pinching on touch devices.
  • Scrolling the mouse wheel or trackpad.

Refer to the following code.

<maps:SfMaps>
 <maps:SfMaps.Layer>
  <maps:MapTileLayer UrlTemplate="https://tile.openstreetmap.org/{z}/{x}/{y}.png" CanCacheTiles="True">
   <maps:MapTileLayer.ZoomPanBehavior>
    <maps:MapZoomPanBehavior EnableDoubleTapZooming="True"/>
   </maps:MapTileLayer.ZoomPanBehavior>
  </maps:MapTileLayer>
 </maps:SfMaps.Layer>
</maps:SfMaps>
Zooming and Panning on OpenStreetMap Using .NET MAUI Maps
Zooming and Panning on OpenStreetMap Using .NET MAUI Maps

Markers

You can show markers at any position in the tile layer. You can use the built-in shapes (circles, diamonds, squares, and triangles) or add any custom content like an image or pin as a marker using the MarkerTemplate support.

Refer to the following code example.

<maps:SfMaps>
 <maps:SfMaps.Layer>
  <maps:MapTileLayer UrlTemplate="https://tile.openstreetmap.org/{z}/{x}/{y}.png" >
   <maps:MapTileLayer.Markers>
    <maps:MapMarkerCollection>
     <maps:MapMarker Latitude="-14.235004" Longitude="-51.92528"
                     IconWidth="10" IconHeight="10" IconFill="White"
                     IconStroke="Black" IconStrokeThickness="2" IconType="Circle" />
     <maps:MapMarker Latitude="51.16569" Longitude="10.451526"
                     IconWidth="10" IconHeight="10" IconFill="White"
                     IconStroke="Black" IconStrokeThickness="2" IconType="Circle" />
     <maps:MapMarker Latitude="-25.274398" Longitude="133.775136"
                     IconWidth="10" IconHeight="10" IconFill="White"
                     IconStroke="Black" IconStrokeThickness="2" IconType="Circle" />
     <maps:MapMarker Latitude="20.593684" Longitude="78.96288"
                     IconWidth="10" IconHeight="10" IconFill="White"
                     IconStroke="Black" IconStrokeThickness="2" IconType="Circle" />
     <maps:MapMarker Latitude="61.52401" Longitude="105.318756"
                     IconWidth="10" IconHeight="10" IconFill="White"
                     IconStroke="Black" IconStrokeThickness="2" IconType="Circle" />
    </maps:MapMarkerCollection>
   </maps:MapTileLayer.Markers>
  </maps:MapTileLayer>
 </maps:SfMaps.Layer>
</maps:SfMaps>
Adding Markers to OpenStreetMap Using .NET MAUI Maps Control
Adding Markers to OpenStreetMap Using .NET MAUI Maps Control

GitHub reference

For more details, refer to the visualizing online map services in the .NET MAUI Maps control GitHub demo.

Conclusion

Thanks for reading! In this blog, we have seen how to visualize online map services using the tile layer support in the Syncfusion .NET MAUI Maps control. Try out this feature and share your feedback in the comments below.

Explore the other features in the .NET MAUI Maps user guide and GitHub demos. Additionally, you can check out our .NET MAUI demo apps on Google Play and Microsoft Store.

If you have any questions, you can reach us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Test Flight
App Center Badge
Google Play Store Badge
Microsoft Badge
Github Store Badge

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed