How Much Does JSR-179 Rock?


Posted

in


In searching for information on JSR-179, the Location API for J2ME, I stumbled across a great article at Sun that shows just how easy geolocating yourself in J2ME can be:

...

/* Set criteria for selecting a location provider:
   accurate to 500 meters horizontally */
Criteria cr= new Criteria();
cr.setHorizontalAccuracy(500);

/* Get an instance of the provider */
LocationProvider lp= LocationProvider.getInstance(cr);

/* Request the location, setting a one-minute timeout */
Location l = lp.getLocation(60);
Coordinates c = l.getQualifiedCoordinates();

if(c != null ) {
  /* Use coordinate information */
  double lat = c.getLatitude();
  double lon = c.getLongitude();
}
...

Does it get any better than that?  It’s simple, easy to use, and now in just a few lines of code you’ve got your latitude and longitude.  Of course if you were grabbing your location in a real-world app, you’d put non-blocking code in a new thread and run it in the background.