setLocationListener not working in Blackberry gps programming

安稳与你 提交于 2019-12-11 07:26:37

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/2235660/setlocationlistener-not-working-in-blackberry-gps-programming

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!