Я использую следующий класс для получения местоположения GPS от blackberry, но я всегда получаю нулевые значения longtude и широты.Почему это так?
public class LocationTracker extends TimerTask {
private double longitude;
private double latitude;
private double altitude;
private LocationProvider lp;
public LocationTracker() {
super();
// Set criteria for selecting a location provider:
Criteria cr = new Criteria();
cr.setCostAllowed(true);
cr.setPreferredResponseTime(60);
cr.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
cr.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
cr.setAltitudeRequired(true);
cr.isSpeedAndCourseRequired();
cr.isAddressInfoRequired();
cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
try {
LocationProvider lp = LocationProvider.getInstance(cr);
Location location = null;
try {
location = lp.getLocation(-1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (LocationException e){
System.out.println(e.toString());
}catch(Exception e ){
System.out.println(e.toString());
}
longitude = location.getQualifiedCoordinates().getLongitude();
latitude = location.getQualifiedCoordinates().getLatitude();
altitude = location.getQualifiedCoordinates().getAltitude();
if (lp != null) {
lp.reset();
lp.setLocationListener(null, -1, -1, -1);
lp = LocationProvider.getInstance(cr);
lp.setLocationListener(new MyLocationListener(), 2, -1, -1);
}
System.out.println("Lon" + longitude + " Lat "+ latitude);
} catch (LocationException le) {
System.out.println(le.toString());
}catch(Exception e ){
System.out.println(e.toString());
}
}
public void run() {
}
public double getLongitude() {
return longitude;
}
public double getLatitude() {
return latitude;
}
public double getAltitude() {
return altitude;
}
private class MyLocationListener implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location) {
if (location != null && location.isValid()) {
QualifiedCoordinates qc = location.getQualifiedCoordinates();
try {
latitude = qc.getLatitude();
longitude = qc.getLongitude();
altitude = qc.getAltitude();
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
public void providerStateChanged(LocationProvider provider, int newState) {
// TODO: if provider was disabled, then disable reporting
}
}
}