Geolocation and Maps in C# (.NET): Libraries, Examples, and Recommendations

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Geolocation and Maps in C# (.NET): Overview of Libraries and Tools



Working with geolocation and maps is a popular task in modern .NET applications: from courier tracking to data visualization on a map. In this article, we will review the main libraries and tools for C# (.NET) that will help you implement geopositioning and map display functionality.



1. Built-in .NET Tools: Windows.Devices.Geolocation Namespace



For UWP (Universal Windows Platform) applications in .NET, a built-in API for obtaining the current device location is available. The main class is Geolocator.



using Windows.Devices.Geolocation;

public async Task<BasicGeoposition> GetCurrentPosition(){ var geolocator = new Geolocator(); geolocator.DesiredAccuracy = PositionAccuracy.High;

Geoposition pos = await geolocator.GetGeopositionAsync(); return pos.Coordinate.Point.Position;}


This method returns the device's latitude and longitude. Important: user permission and enabled GPS/network are required for it to work.



2. GeoCoordinate Library (System.Device.Location)



The GeoCoordinate class from System.Device.Location is available for classic .NET Framework applications (Windows Forms, WPF). It allows not only obtaining coordinates but also calculating the distance between two points.



using System.Device.Location;

public double CalculateDistance(double lat1, double lon1, double lat2, double lon2){ var coord1 = new GeoCoordinate(lat1, lon1); var coord2 = new GeoCoordinate(lat2, lon2); return coord1.GetDistanceTo(coord2); // in meters}


For .NET Core / .NET 5+ this library is not available — use the alternatives described below.



3. Working with Maps: MapControl (WPF/UWP)



In WPF and UWP, you can use the built-in MapControl element from Windows.UI.Xaml.Controls.Maps. It allows displaying Bing Maps (by default) or connecting third-party tiles.



<!-- XAML markup --><Maps:MapControl x:Name="MyMap"                  ZoomLevel="12"                  Center="55.7558, 37.6173" />


To add pushpins (markers), use MapIcon:



using Windows.Devices.Geolocation;using Windows.UI.Xaml.Controls.Maps;

public void AddMarker(double latitude, double longitude, string title){ var pin = new MapIcon { Location = new Geopoint(new BasicGeoposition { Latitude = latitude, Longitude = longitude }), Title = title, NormalizedAnchorPoint = new Point(0.5, 1.0) }; MyMap.MapElements.Add(pin);}


4. Google Maps API for .NET



To work with Google Maps from C# (.NET Core / .NET 5+), use the GoogleMapsApi library (NuGet: GoogleMapsApi). It provides a convenient interface for geocoding, reverse geocoding, and route planning.



using GoogleMapsApi;using GoogleMapsApi.Entities.Geocoding.Request;using GoogleMapsApi.Entities.Geocoding.Response;

public async Task<GeocodingResponse> GeocodeAddress(string address){ var request = new GeocodingRequest { Address = address, ApiKey = "YOUR_API_KEY" }; var geocodingEngine = new GeocodingEngine(); return await geocodingEngine.GeocodeAsync(request);}


Don't forget to get an API key from the Google Cloud Console and enable billing (free limit — 40,000 requests/month).



5. NetTopologySuite Library for Working with Geometry



If you need to analyze geographic data (polygons, lines, points), use NetTopologySuite (NTS). This is a port of the Java JTS library for .NET.



using NetTopol                    

Recommendations