黑莓问题的蜂窝网站GPS跟踪

时间:2011-10-14 08:20:07

标签: blackberry gps

在我的BB应用中,我尝试使用手机网站获取位置。

但它总是抛出一个位置异常:

Timed out while waiting for Geolocation.m=0

这是我的代码

Criteria criteria = new Criteria();
criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
criteria.setCostAllowed(true);
criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
LocationProvider provider = LocationProvider.getInstance(criteria);
Location location = provider.getLocation(-1);
QualifiedCoordinates qualifiedCoordinates = location.getQualifiedCoordinates();
double latitude = qualifiedCoordinates.getLatitude();
double longitude = qualifiedCoordinates.getLongitude();

但如果我将参数更改为

criteria.setHorizontalAccuracy(50);
criteria.setVerticalAccuracy(50);
criteria.setCostAllowed(true);
criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);

辅助GPS工作正常,我将获得正确的设备位置。

2 个答案:

答案 0 :(得分:0)

class LocationTracker{
private LocationProvider provider;
Criteria cr;
public LocationTracker() {
    cr= new Criteria();
    resetGPS();
}

public void resetGPS(){       
        try {
            provider = LocationProvider.getInstance(cr);
            if(provider != null) {
                    provider.setLocationListener(new MyLocationListener(),60, -1, -1);
            }
        }
        catch (LocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }     
    }
}

class MyLocationListener implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location){
    if(location != null && location.isValid()){               
        QualifiedCoordinates qc = location.getQualifiedCoordinates();
        try {
            LAT = location.getQualifiedCoordinates().getLatitude();
            System.out.println("=============================lattitude :: "+LAT);
            LONG= location.getQualifiedCoordinates().getLongitude();
            System.out.println("==================================longitude ::"+LONG);

        } 
        catch(Exception e){ 
           }
    }
}

public void providerStateChanged(LocationProvider provider, int newState){
     if(newState == LocationProvider.TEMPORARILY_UNAVAILABLE){
            provider.reset();
            provider.setLocationListener(null, 0, 0, -1);
        }
    }
}

答案 1 :(得分:0)

与vijay一样,您可以注册到位置更新。

如果您仍想使用您的解决方案,则必须确保这一点 - 它是线程化的(并且不仅仅是为了获得ANR,这是一个要求) - 您有一张带Blackberry选项的SIM卡 - 你至少运行OS 5.0.0