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

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): Tools for Working with Spatial Data



Developing applications that work with geographic coordinates, maps, and routes is a popular task for C# developers. The .NET ecosystem has several powerful libraries that allow you to solve tasks from simple coordinate determination to building complex geographic information systems (GIS). In this article, we will review the key tools for working with geolocation and maps in C#.



1. Built-in Tools: The GeoCoordinate Class



The .NET platform provides a base class System.Device.Location.GeoCoordinate (available in .NET Framework and via the System.Device.Location.Portable package for .NET Core). It allows you to store latitude and longitude, as well as calculate the distance between two points using the haversine formula.



using System.Device.Location;

public class GeoService{ public double CalculateDistance(double lat1, double lon1, double lat2, double lon2) { var point1 = new GeoCoordinate(lat1, lon1); var point2 = new GeoCoordinate(lat2, lon2); return point1.GetDistanceTo(point2); // result in meters }

public void ShowDistance() { double distance = CalculateDistance(55.7558, 37.6176, 59.9343, 30.3351); Console.WriteLine($"Distance Moscow-St. Petersburg: {distance / 1000:F2} km"); }}


Limitations: the class does not support working with maps, geocoding (converting an address to coordinates), or route building. For full-fledged map work, third-party libraries are required.



2. Mapsui — Cross-Platform Library for Displaying Maps



Mapsui is a modern cross-platform library for .NET (supports WPF, MAUI, Avalonia, Blazor). It allows you to display maps from various sources: OpenStreetMap (OSM), Bing Maps, Stamen, as well as custom tile servers. The library is open-source and actively developed.



Key Features:

  • Displaying raster and vector tiles
  • Support for layers (markers, polygons, lines)
  • Interactivity: zooming, panning, clicking on objects
  • Integration with map providers (OSM, CartoDB, MapTiler)
  • Support for projections (EPSG:4326, EPSG:3857)


using Mapsui;using Mapsui.Providers;using Mapsui.Tiling;using Mapsui.Widgets.MapInfo;using Mapsui.Widgets;

// Create a map with OpenStreetMap tilesvar map = new Map();map.Layers.Add(OpenStreetMap.CreateTileLayer());

// Add a marker (point)var pointLayer = new MemoryLayer{ DataSource = new PointsProvider(new[] { new Feature(new MPoint(37.6176, 55.7558)) { ["Name"] = "Moscow" } }), Style = new SymbolStyle { Fill = new Brush(Color.Red), SymbolScale = 1.5 }};map.Layers.Add(pointLayer);

// Display in WPF MapControl// mapControl.Map = map;


When to use: if you need to embed a map into a desktop or mobile application on .NET MAUI/WPF, independent of third-party API keys (OSM is free).



3. NetTopologySuite (NTS) — Working with Geometry and Spatial Queries



NetTopologySuite is a port of the well-known Java library JTS (Java Topology Suite) for .NET. It provides powerful tools for working with geometric objects: points, lines, polygons, multipolygons. NTS is used as the foundation for many GIS applications and ORMs (e.g., Entity Framework Core with the Npgsql provider for PostgreSQL/PostGIS).



Key Features:

  • Creating and manipulating geometric shapes
  • Spatial predicates: intersection, containment, touching
  • Buffering, union, intersection of polygons
  • Reading/writing formats

Recommendations