View on GitHub Sample viewer app

Display your position on the map and switch between different types of autopan modes.

Image of display device location with autopan modes

Use case

When using a map within a GIS, it may be helpful for a user to know their own location within a map, whether that’s to aid the user’s navigation or to provide an easy means of identifying/collecting geospatial information at their location.

How to use the sample

The sample loads with a symbol marking a simulated location on the map. Explore the available autopan modes by selecting an option from the drop down box:

  • Off - Shows the location with no autopan mode set.
  • Re-Center - In this mode, the map re-centers on the location symbol when the symbol moves outside a “wander extent”.
  • Navigation - This mode is best suited for in-vehicle navigation.
  • Compass - This mode is better suited for waypoint navigation when the user is walking.

Uncheck the box to stop the location display.

How it works

  1. Create a MapView.
  2. Get the LocationDisplay object by calling getLocationDisplay() on the map view.
  3. Create a SimulatedLocationDataSource and call its setLocations() method, passing the route Polyline and new SimulationParameters as parameters.
  4. Start the location display with startAsync() to begin receiving location updates.
  5. Use locationDisplay.setAutoPanMode() to change how the map view behaves when location updates are received.

Relevant API

  • LocationDisplay
  • LocationDisplay.AutoPanMode
  • MapView
  • SimulatedLocationDataSource
  • SimulationParameters

Additional information

A custom set of points (provided in JSON format) is used to create a Polyline and configure a SimulatedLocationDataSource. The simulated location data source enables easier testing and allows the sample to be used on devices without an actively updating GPS signal. To display a user’s real position, use NMEALocationDataSource instead.

Tags

compass, GPS, location, map view, mobile, navigation

Sample Code

module-info.java module-info.java DisplayDeviceLocationWithAutopanModesSample.java
/*
* Copyright 2022 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module com.esri.samples.display_device_location_with_autopan_modes {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
// require other modules the application uses
requires org.apache.commons.io;
exports com.esri.samples.display_device_location_with_autopan_modes;
}