Cross-platform Maps with .NET MAUI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
>> [MUSIC] >> Hi, I'm James Montemagno and today I want to talk to you about a brand-new feature introduced in.NET 7 for.Net MAUI, which is cross-platform maps supporting iOS, Android, and Mac catalyst. Now with.Net MAUI maps, there are a lot of different features including just showing a map, putting pins and multiple pins on a map, and even at drawing regions. Additionally, you have four options for the type of map that you want to display. Whether it is a hybrid map, satellite view, or street map, you can turn on and off traffic and a lot more. Today I want to show you how to get set up actually using.Net MAUI maps and then of course how to implement some of these features. Let's take a look. First thing that you'll need to do is install a NuGet Package for Microsoft Maui controls maps. Since this uses some additional native NuGet packages on Android and some other dependencies, this NuGet package isn't included by default, so you have to add maps into your projects. Since not every single application needs maps, this is going to ensure if you're not using maps, there's no additional overhead that's needed. Once you install this NuGet package, you'll need to initialize the NuGet package inside of your app startup. You can add on the Use Maui maps extension method inside of your Maui app builder. This is going to handle everything to initialize the maps on the different platforms. After we've initialized the maps, there's a little bit more setup that we need to do. For iOS, Android, and Mac, you can optionally request location permission if you want to show your user's location on the map. That's a nice thing to do and there's great documentation that walks you through how to do this. On Android, since we are using Google Maps and the dependencies there, you will have to configure a Google Maps API key and set up the Google Play version information in your AndroidManifest. Now I'll link to all the documentation to walk you through everything you need to know. Now, let's go ahead and display a map. You can do this in XAML or in C-sharp, and your code behind, you will first add in the namespace of Microsoft MAUI controls maps, and then add a map control. You can specify different settings like map type and if you want to show traffic and other things as well, so be sure to read the documentation and do so. Now if we want to display a region on the map, all we have to do is go ahead and create the location, create the map span and what our zoom level is, and then move to the region. You can also do this in XAML as well. However, I prefer the nice small bit of code here and the code behind. Just like that, will have a map that zoomed in on a specific region. Now, another thing you might want to do is add a pin to this map and it's really easy. In fact, all you have to do is specify a new pin which has a label, address, the type of pin, and the location on the map, and the map control itself has a series of pins. Again, you can do this in code behind, or you can do it in XAML. There we go. There's our pin right on our map. All right, next up our polygons, polylines, and circles. This is something that is really nice if you're doing some GeoJSON, for example, or you are tracking your user's location in a driving application and you want to draw a line on the map. Now these three different types of aliments do different things. First, the polygon, you can think of it as a fully enclosed shape. The first and last points are automatically connected for you if they're not the same. A polyline is a series of points connected by drawn lines. That's that example if you're drawing your rap on a map. Then finally it's a circle. It's drawn from a center point with a specified radius, and colors and outline colors as well. Let's take a look at an example of that circle. All you need to do is create a circle. In here, you add it to the map elements. Just like polyline and polygon, you create these different elements and add it to the list of map elements that will be displayed, natively using the native map controls. There you have it. You have everything you need to start creating beautiful maps with.Net MAUI and iOS, Android, and Mac. You can get started today, go to dot.net/maui and check out all of the documentation, and I'll put links in the show notes below. Thanks for watching. >> [MUSIC]
Info
Channel: dotnet
Views: 10,381
Rating: undefined out of 5
Keywords: .NET
Id: jkEWltr6Aq0
Channel Id: undefined
Length: 4min 33sec (273 seconds)
Published: Wed Feb 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.