Track GPS

This sample demonstrates how to add elements to a map's graphics container, then move them in response to a timer. It also demonstrates how to set a coordinate system and project data.
This sample application uses the AddShapeFile method to load sample world data, which is then symbolized. The SpatialReference property of the MapControl is set to a projected coordinate system (PCS [esriSRProjCS_World_Mollweide]). Points are created from an array containing latitude and longitude values and are given a SpatialReference property set to a geographic coordinate system (GCS [esriSRGeoCS_WGS1984]). Each point is then projected onto the PCS of the MapControl and added to its graphics container.
When Global Positioning System (GPS) tracking is enabled, a timer is used to randomly assign new x,y coordinates to each point in the graphics container after a specified time interval. Each point is projected onto the GCS to ensure that it resides within the horizon of the esriSRGeoCS_WGS1984 coordinate system. Each point is then projected back onto the PCS (esriSRProjCS_World_Mollweide) of the MapControl, before the graphics are refreshed, to reflect the change in their geometry.
The OnMouseDown event uses the TrackRectangle method to zoom in if the left mouse button is pressed, or creates a point based on the location of the mouse pointer if the middle or right mouse button is pressed. A polygon is created by buffering the point using the ITopologicalOperator interface and is then drawn on the MapControl using the DrawShape method. Each element in the graphics container is tested using the IRelationalOperator interface to determine whether it is contained by the polygon. If a point is contained by the polygon, its symbol is changed.

How to use

See How to use ArcGIS samples for help on running the sample.

  1. Run the TrackGPS application.
  2. Toggle between enabling and disabling GPS tracking.
  3. Use the left mouse button to zoom in and the other mouse buttons to buffer a point and create a polygon. If any of the agents are within the polygon, their symbology is changed.

If you installed the samples feature, you will find the files associated with this sample in <Your Developer Kit install location>\DeveloperKit10.4\Java\Samples\ArcObjects.

mapbean/ Main class.

Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced