Development Guide

Local Navigation

Code sample: Retrieving the GPS location of a BlackBerry device

import javax.microedition.location.*;

public class handleGPS
{
    static GPSThread gpsThread;
    static double latitude;
    static double longitude;

    public handleGPS()
    {
        gpsThread = new GPSThread();
        gpsThread.start();
    }

    private static class GPSThread extends Thread
    {
        public void run()
        {
            Criteria myCriteria = new Criteria();
            myCriteria.setCostAllowed(false);

            try
            {
                LocationProvider myLocationProvider =
                    LocationProvider.getInstance(myCriteria);

                try
                {
                    Location myLocation = myLocationProvider.getLocation(300);
                    latitude  = myLocation.getQualifiedCoordinates().getLatitude();
                    longitude = myLocation.getQualifiedCoordinates().getLongitude();
                }
                catch ( InterruptedException iex )
                {
                    return;
                }
                catch ( LocationException lex )
                {
                    return;
                }
            }
            catch ( LocationException lex )
            {
                return;
            }
            return;
        }
    }
}

Was this information helpful? Send us your comments.