Back | Tutorial Home | Next
Location API gives you the ability to know whether a particular mobile use is within proximity of a particular location. ProximityListener Interface has to be implemented to track the proximity event.
ProximityListener has two methods which have to be overridden.
monitoringStateChanged(boolean
isMonitoringActive) : Called to notify that the state of the proximity
monitoring has changed.
proximityEvent(Coordinates coordinates, Location location): This method
will have your code for tasks to be done when the user comes into proximity
to a particular location.
This listener is registered
to LocationProvider by calling its static method addProximityListener().
addProximityListener(ProximityListener listener, Coordinates coordinates,
float proximityRadius)
Parameter Description
listener: Class implementing
ProximityListener Interface.
coordinates: coordinates for which proximity is checked.
proximityRadius: The radius in meters which forms the arc around the
coordinates registered.
The code segment for registration
try {
Criteria cr = new Criteria();
// Required Accuracy is set to 100 Meters
provider = LocationProvider.getInstance(cr);
// coordinates around which proximity has to be found
Coordinates myCoordinates = new Coordinates(14.389796709, 50.099850027, 310);
// Listener registration for above coordinates for proximity of 1000 meters.
LocationProvider.addProximityListener(this, myCoordinate, 1000.0f);
} catch (LocationException e) {
e.printStackTrace();
}
Code segment for proximityEvent()
public void proximityEvent(Coordinates arg0, Location arg1) {
// Display results on form
resultsForm = new Form("Proximity Result");
String displayString = "You are presently within 1000 meters radius from Location
\n\nLat: 14.389796709\nLong: 50.099850027" ;
resultsForm.append(displayString);
cmdExit = new Command("Exit", Command.SCREEN, 0);
resultsForm.addCommand(cmdExit);
display.setCurrent(resultsForm);
resultsForm.setCommandListener(this);
}
|
| j2meSasa goodies | |
| Download demo code for deploying directly to WTK | Click here to download Zip File Containing WTK compatible file structure. This zip file is a MIDlet suite of all the examples in this in this LBS tutorial |
Back
| Tutorial Home | Next
More Tutorials
This page is a part of
a frames based web site. If you have landed on this page from a search engine
click here to view the complete page.