When LocationProvider
has been successfully
created, it can be used to register the MIDlet to listen for regular
location updates and to detect certain coordinate proximity. Current
location update and location provider state change events can be listened
to through the LocationListener
interface (see
the following code sample). Through this interface a JSR-179 application
may track a device's route.
Code sample: LocationListener interface's skeleton (TouristRoute's TouristData.java class)
public void locationUpdated(LocationProvider provider, final Location location) public void providerStateChanged(LocationProvider provider, final int newState)
Note: The standard LocationListener
interface
does not set the location
or newState
parameters as final. In the example, the final
keyword is used on parameters to enable the anonymous thread implementation
to access the reference. In the TouristRoute example, both implemented
methods start a new thread, because LocationListener
methods should return quickly without performing any extensive processing.
Through ProximityListener
, the interface MIDlet
obtains notifications when a registered coordinate is detected (see
the following code sample). Proximity event listening makes it possible
to monitor when the device arrives in a certain area, for example
close to a hotel or restaurant.
Code sample: Proximity listener's skeleton (TouristRoute's TouristData class)
public void proximityEvent(Coordinates coordinates, Location location) public void monitoringStateChanged(boolean isMonitoringActive)