Format coordinates

View inMAUIUWPWPFWinUIView 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

Click on the map to see a callout with the clicked 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.xamlFormatCoordinates.xamlFormatCoordinates.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<UserControl
    x:Class="ArcGIS.UWP.Samples.FormatCoordinates.FormatCoordinates"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <UserControl.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="FontWeight" Value="SemiBold" />
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="Margin" Value="0,5,5,0" />
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="0,5,0,0" />
            <Setter Property="TextWrapping" Value="Wrap" />
            <Setter Property="Width" Value="210" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock
                    Text="Tap on the map to see the coordinates in each format. Update any value and tap 'Recalculate' to see the updated coordinates."
                    Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                    Margin="0,0,0,5" MaxWidth="400"
                    HorizontalAlignment="Stretch"
                    TextWrapping="Wrap" />
                <TextBlock Text="Decimal Degrees:"
                           Grid.Row="1" Grid.Column="0" />
                <TextBox x:Name="DecimalDegreesTextField"
                         Grid.Row="1" Grid.Column="1"
                         Tag="Decimal Degrees" />
                <TextBlock Text="DMS:"
                           Grid.Row="2" Grid.Column="0" />
                <TextBox x:Name="DmsTextField"
                         Grid.Row="2" Grid.Column="1"
                         Tag="Degrees, Minutes, Seconds" />
                <TextBlock Text="UTM:"
                           Grid.Row="3" Grid.Column="0" />
                <TextBox x:Name="UtmTextField"
                         Grid.Row="3" Grid.Column="1"
                         Tag="UTM" />
                <TextBlock Text="USNG:"
                           Grid.Row="4" Grid.Column="0" />
                <TextBox x:Name="UsngTextField"
                         Grid.Row="4" Grid.Column="1"
                         Tag="USNG" />
                <Button Content="Recalculate"
                        Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2"
                        HorizontalAlignment="Stretch"
                        Margin="0,5,0,0"
                        Click="RecalculateFields" />
            </Grid>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close