我正在開發具有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;
}
我在做什麼錯誤請在我的代碼中幫助我。 Thanx提前。
thanx的Replay..really這項工作精細。 – Hasmukh 2012-01-16 13:22:09