ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Core.UnitFormats Namespace / DisplayUnitFormat Class / FormatLocation Method / FormatLocation(Coordinate2D,SpatialReference) Method
Example

In This Topic
    FormatLocation(Coordinate2D,SpatialReference) Method
    In This Topic
    Format the input location using the location unit format. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public string FormatLocation( 
       Coordinate2D location,
       SpatialReference sr
    )
    Public Overloads Function FormatLocation( _
       ByVal location As Coordinate2D, _
       Optional ByVal sr As SpatialReference _
    ) As String

    Parameters

    location
    sr

    Return Value

    A formatted location string
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run
    Remarks
    The UnitFormatType must be of type UnitFormatType.Location or an empty string will be returned.
    If the spatial reference is null then WGS84 is assumed.
    Example
    Format a Location Using the Current Map Location Unit
    var mv = MapView.Active;
    var map = mv.Map;
    
    QueuedTask.Run(() =>
    {
      //Get the current view camera location
      var center_pt = new Coordinate2D(mv.Camera.X, mv.Camera.Y);
      //Get the current location unit
      var loc_unit = map.GetLocationUnitFormat();
    
      //Format the camera location
      var str = loc_unit.FormatLocation(center_pt, map.SpatialReference);
      System.Diagnostics.Debug.WriteLine($"Formatted location: {str}");
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also