tags:

views:

264

answers:

2

I am working on gps based application. I am using LocationProvider and calling setlocationListener through it code is like


   LocationProvider lp = LocationProvider.getInstance(null);
        if (lp != null) {
            lp.setLocationListener(new LocationListenerImpl(), 2, 1, 1);
        } else {
            Dialog.alert("GPS NOT SUPPORTED!");
            retval = false;
        }
    } catch (LocationException e) {
        System.out.println("GPS Error: " + e.toString());
    }

    return retval;
}

private class LocationListenerImpl implements LocationListener {
    public void locationUpdated(LocationProvider provider, Location location) {
        if (location.isValid()) {
            heading = location.getCourse();
            longitude = location.getQualifiedCoordinates().getLongitude();
            latitude = location.getQualifiedCoordinates().getLatitude();
            altitude = location.getQualifiedCoordinates().getAltitude();
            speed = location.getSpeed();
            System.out.println("Current latitude:"+latitude);
            System.out.println("Current longitude:"+longitude);
            System.out.println("Current speed:"+speed);

            // This is to get the Number of Satellites
            String NMEA_MIME = "application/X-jsr179-location-nmea";
            satCountStr = location.getExtraInfo("satellites");
            if (satCountStr == null) {
                satCountStr = location.getExtraInfo(NMEA_MIME);
            }

            // this is to get the accuracy of the GPS Cords
            QualifiedCoordinates qc = location.getQualifiedCoordinates();
            accuracy = qc.getHorizontalAccuracy();
        }
    }

it doesnt give an error but dont even work out so help with the same.the control dont get transferred to LocationListenerImpl()... I am using BlackBerry_JDE_PluginFull_1.0.0.67 with eclipse-java-galileo-SR1-win32 on Blackberry 8800 simulator.. Any assistence is grately appreciated.... Thanking you in advance.

A: 

try this:

lp.setLocationListener(new LocationListenerImpl(), 2, -1, -1);

Acc to me u set 2,1,1 which means that time interval is 2 sec after which location updation will be automatically called 1 sec indicates time out 1 sec indicates max age

ur gps times out before going ahead for gps location update method.so try it with setting it to default value = -1

SWATI
A: 

You have to enable the GPS in the simulator, is it enabled when you try?

If you're getting a NullPointerException then you should check in the OS Options that the GPS has Location activated.

Curro