【发布时间】:2012-01-06 11:29:49
【问题描述】:
我正在开发具有 GPS 功能的黑莓应用程序。所以首先我想获取当前的纬度和经度,但它会像 在等待 GPS 定位时超时。 下面在我的代码中获取当前位置的纬度和经度。
public class LocationScreen extends MainScreen
{
public LocationScreen()
{
super();
final LabelField lfLocation = new LabelField();
new Thread()
{
public void run()
{
LocationHandler lh = new LocationHandler();
final String msg = "Long: " + lh.getCurrentLongitude() + ", Lat: " + lh.getCurrentLatitude();
Application.getApplication().invokeLater(new Runnable()
{
public void run()
{
lfLocation.setText(msg);
add(new LabelField("Lat and Long=="+msg));
}
});
}
}.start();
this.add(lfLocation);
}
}
**Second Class**
public class LocationHandler
{
private LocationProvider locationProvider;
private Location currentLocation;
public LocationHandler()
{
try
{
locationProvider = LocationProvider.getInstance(null);
currentLocation = locationProvider.getLocation(60);
}
catch (final Exception e)
{
Application.getApplication().invokeLater(new Runnable()
{
public void run()
{
Status.show(e.getMessage());
}
});
}
}
public double getCurrentLongitude()
{
if(currentLocation != null)
return currentLocation.getQualifiedCoordinates().getLongitude();
return -1;
}
public double getCurrentLatitude()
{
if(currentLocation != null)
return currentLocation.getQualifiedCoordinates().getLatitude();
return -1;
}
我在代码中做错了什么,请帮助我。 提前谢谢。
【问题讨论】:
标签: blackberry