ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping.DeviceLocation Namespace / MapDeviceLocationService Class / SetDeviceLocationOptions Method
A MapDeviceLocationOptions
Example

In This Topic
    SetDeviceLocationOptions Method (MapDeviceLocationService)
    In This Topic
    Sets a MapDeviceLocationOptions to update the current MapDeviceLocationService settings. This method must be called on the MCT. Use QueuedTask.Run. Use QueuedTask.Run.
    Syntax
    public void SetDeviceLocationOptions( 
       MapDeviceLocationOptions options
    )
    Public Sub SetDeviceLocationOptions( _
       ByVal options As MapDeviceLocationOptions _
    ) 

    Parameters

    options
    A MapDeviceLocationOptions
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Value cannot be null: options
    The active map view cannot be null
    A DeviceLocationSource must be open
    Remarks
    A valid DeviceLocationSource must be open or a System.InvalidOperationException will be thrown. Refer to ArcGIS.Desktop.Core.DeviceLocation.IDeviceLocationService.Open.
    There must be an active map view with an associated map.
    Example
    Set Current Map Device Location Options
    //Must be on the QueuedTask.Run()
    
    //Check there is a source first...
    if (DeviceLocationService.Instance.GetSource() == null)
      //Setting DeviceLocationOptions w/ no Device Location Source
      //Will throw an InvalidOperationException
      return;
    
    var map = MapView.Active.Map;
    if (!MapDeviceLocationService.Instance.IsDeviceLocationEnabled)
      //Setting DeviceLocationOptions w/ no Device Location Enabled
      //Will throw an InvalidOperationException
      return;
    
    MapDeviceLocationService.Instance.SetDeviceLocationOptions(
      new MapDeviceLocationOptions()
      {
        DeviceLocationVisibility = true,
        NavigationMode = MappingDeviceLocationNavigationMode.KeepAtCenter,
        TrackUpNavigation = true
      });
    
    Set map view to always be centered on the device location
    var currentOptions = MapDeviceLocationService.Instance.GetDeviceLocationOptions();
    if (currentOptions == null)
      return;
    
    currentOptions.DeviceLocationVisibility = true;
    currentOptions.NavigationMode = MappingDeviceLocationNavigationMode.KeepAtCenter;
    
    await QueuedTask.Run(() =>
    {
      MapDeviceLocationService.Instance.SetDeviceLocationOptions(currentOptions);
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also