Global Positioning System Reference
In-Depth Information
The GPSapplication class and main method were written to demon-
strate the usage of every class and interface in the roaf.book.gps
package.
Note that the method gpsUnitDemo() requires resources from your
hard drive. Please refer to the Appendix for instructions on down-
loading the resources and adapting the paths to your environment.
It is advised to run the method GPSapplication.main now and make
sure the resource GPX file is allocated properly. Then, you can ana-
lyze the details of the demo class as you progress through the rest of
this chapter.
4.4
A Route to Manage an Array of Position s
A route is an ordered list of geographical locations (lat,lon) and rep-
resents an essential tool to handle spatial data in various contexts. Java
comes with the Collection Framework and provides a number of implemen-
tations to collect objects. Our real-world constructs are not included there
and must be developed separately.
Please execute the method roaf.book.gps.GPSapplication.main and
study the invoked method routeTraceDemo() as you proceed through
Sections 4.4{4.7. You can chose to comment out the method
gpsUnitDemo() for now.
A new class roaf.book.gps.Route is created to hold the private member
ArrayListroute . Since private members are not externally accessible they
are \wrapped" in the class and the developer can add external access to
dedicated members of the hidden class. \Wrapping" the route in the class
is a good approach and allows you to later unwrap the ArrayList API step-
by-step in the development process. This way you can control the visibility
of methods as needed.
Although the ArrayList is hidden inside the Route class, the programmer
should be aware that a collection generally holds object references. There-
fore, a location of a route can be modified without updating the route
attributes. To emphasize this fact, the method Position.getNewPosition()
is added to the interface. Every location object implementing a position
should provide a method to create a new location as a copy:
roaf.book.gps.Route
public void appendPosition( Position point )
{
// encapsulate a new object as new Position
sequence.add( point.getNewPosition() );
Search WWH ::




Custom Search