Track GPS


Purpose
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 (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 (esriSRGeoCS_WGS1984). Each point is then projected onto the projected coordinate system 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 and y coordinates to each point in the graphics container after a specified time interval. Each point is projected onto the geographic coordinate system to ensure that it resides within the horizon of the esriSRGeoCS_WGS1984 coordinate system. Each point is then projected back onto the projected coordinate system (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. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  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.


Download the files for Java
mapbean/TrackGPS.java Main class




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo