1

我目前正在开发一个 BB 应用程序,我需要获得我目前的职位。

在带有 v5.0 的 BB 模型中没问题,但在带有 v6.0 的 BB 中,我总是将 locationProvider 设为空。(GPS 已打开)。

任何人都知道会发生什么以及如何解决它?

我使用的一段代码是:

private boolean startLocationUpdate() {
    boolean retval = false;

    try {
        Criteria criteria = new Criteria();
        criteria.setCostAllowed(true);
        criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);

        criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);

        locationProvider = LocationProvider.getInstance(criteria);

        if (locationProvider == null) {

            Runnable showGpsUnsupportedDialog = new Runnable() {
                public void run() {

                    Dialog.alert("GPS is not supported on this platform...");
                    // System.exit( 1 );
                }
            };

            UiApplication.getUiApplication().invokeAndWait(
                    showGpsUnsupportedDialog); // Ask event-dispatcher
                                                // thread to display dialog
                                                // ASAP.
        } else {

            locationProvider.setLocationListener(
                    new LocationListenerImpl(), interval, 1, 1);

            retval = true;
        }
    } catch (LocationException le) {
        System.err
                .println("Failed to instantiate the LocationProvider object, exiting...");
        System.err.println(le);
        System.exit(0);
    }
    return retval;
}

谢谢!

4

1 回答 1

0

根据Criteria的 API 文档,您正在请求 Cellsite 模式。LocationProvider.getInstance()的文档指定:

a LocationProvider meeting the defined criteria or null if a LocationProvider that meets the defined criteria can't be returned but there are other supported available or temporarily unavailable providers that do not meet the criteria.

因此 API 告诉您不支持 Cellsite,但还有其他支持的模式可用。如果您想使用 GPS,您需要指定一个要求自主模式的标准。

于 2012-05-29T13:59:05.560 回答