i am developing app in Blackberry which have GPS Functionality. so first i want to get Current latitude and longitude but it will dipslay like time out while waiting for GPS loaction. Below in my code for getting lat and long of current location.
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;
}
what i am doing mistake in my code please help me.
Thanx in advance.
Make simple
Threadand write down below code inrun method.Try this it working fine in my device using
BIS.i hope it will help you ..