View in MAUI WPF WinUI View on GitHub

Format coordinates in a variety of common notations.

Images of format coordinates

Use case

The coordinate formatter can format a map location in WGS84 in a number of common coordinate notations. Parsing one of these formats to a location is also supported. Formats include decimal degrees; degrees, minutes, seconds; Universal Transverse Mercator (UTM), and United States National Grid (USNG).

How to use the sample

Tap on the map to see a callout with the tapped location’s coordinate formatted in 4 different ways. You can also put a coordinate string in any of these formats in the text field. Hit Enter and the coordinate string will be parsed to a map location which the callout will move to.

How it works

  1. Get or create a MapPoint with a spatial reference.
  2. Use one of the static “to” methods on CoordinateFormatter such as CoordinateFormatter.ToLatitudeLongitude(point, CoordinateFormatter.LatitudeLongitudeFormat.DecimalDegrees, 4) to get the formatted string.
  3. To go from a formatted string to a Point, use one of the “from” static methods like CoordinateFormatter.FromUtm(coordinateString, map.SpatialReference, CoordinateFormatter.UtmConversionMode.NorthSouthIndicators).

Relevant API

  • CoordinateFormatter
  • CoordinateFormatter.LatitudeLongitudeFormat
  • CoordinateFormatter.UtmConversionMode

Tags

convert, coordinate, decimal degrees, degree minutes seconds, format, latitude, longitude, USNG, UTM

Sample Code

FormatCoordinates.xaml FormatCoordinates.xaml FormatCoordinates.xaml.cs
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGIS.Samples.FormatCoordinates.FormatCoordinates"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Maui;assembly=Esri.ArcGISRuntime.Maui">
<Grid Style="{DynamicResource EsriSampleContainer}">
<esriUI:MapView x:Name="MyMapView" Style="{DynamicResource EsriSampleGeoView}" />
<Border MinimumWidthRequest="400" Style="{DynamicResource EsriSampleControlPanel}">
<Grid ColumnDefinitions="*,*"
ColumnSpacing="5"
RowDefinitions="auto,auto,auto,auto,auto"
RowSpacing="5">
<Label Grid.Row="0"
Grid.Column="0"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center">
Decimal Degrees
</Label>
<Entry x:Name="DecimalDegreesTextField"
Grid.Row="0"
Grid.Column="1"
Placeholder="Decimal Degrees" />
<Label Grid.Row="1"
Grid.Column="0"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center">
Degrees, Minutes, Seconds
</Label>
<Entry x:Name="DmsTextField"
Grid.Row="1"
Grid.Column="1"
Placeholder="Degrees, Minutes, Seconds" />
<Label Grid.Row="2"
Grid.Column="0"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center">
UTM
</Label>
<Entry x:Name="UtmTextField"
Grid.Row="2"
Grid.Column="1"
Placeholder="UTM" />
<Label Grid.Row="3"
Grid.Column="0"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center">
USNG
</Label>
<Entry x:Name="UsngTextField"
Grid.Row="3"
Grid.Column="1"
Placeholder="USNG" />
<Button Grid.Row="4"
Grid.Column="0"
Grid.ColumnSpan="2"
Clicked="RecalculateFields"
Text="Recalculate" />
</Grid>
</Border>
</Grid>
</ContentPage>