黑莓 GPS 的经度和纬度返回零
Posted
技术标签:
【中文标题】黑莓 GPS 的经度和纬度返回零【英文标题】:Blackberry GPS returns zero for longitude and latitude 【发布时间】:2011-06-28 07:29:23 【问题描述】:我正在使用以下类从黑莓获取 GPS 位置,但我总是得到零经度和纬度值。这是为什么呢?
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
【问题讨论】:
【参考方案1】:您是否从设置中检查 gps 状态?如果它正在工作,请尝试将超时值设置为大约 300 秒而不是 -1。
【讨论】:
【参考方案2】:LocationProvider
可能会返回一个Location
对象,该对象具有isValid()
false
。这样做是为了通过getExtraInfo()
方法提供更多信息。
【讨论】:
以上是关于黑莓 GPS 的经度和纬度返回零的主要内容,如果未能解决你的问题,请参考以下文章