I am calling startLocationUpdate() in BlackBerry simulator 9800 to get coordinates (latitude,longitude) of where I am, i.e. in UAE. However I get coordinates for Canada. What does this mean? Is the GPS not working? I tried checking settings for the simulator and I do not see any option to "turn GPS on". Please guide how to obtain my current location.
private boolean startLocationUpdate()
{
boolean retval = false;
try
{
locationProvider = LocationProvider.getInstance(null);
if ( locationProvider == null )
{
Runnable showGpsUnsupportedDialog = new Runnable()
{
public void run()
{
Dialog.alert("GPS is not supported on this platform, exiting...");
//System.exit( 1 );
}
};
UiApplication.getUiApplication().invokeAndWait( showGpsUnsupportedDialog ); // Ask event-dispatcher thread to display dialog ASAP.
}
else
{
locationProvider.setLocationListener(new LocationListenerImpl(), interval, -1, -1);
retval = true;
}
}
catch (LocationException le)
{
System.err.println("Failed to instantiate the LocationProvider object, exiting...");
System.err.println(le);
System.exit(0);
}
return retval;
}
private class LocationListenerImpl implements LocationListener
{
public void locationUpdated(LocationProvider provider, Location location)
{
if(location.isValid())
{
longitude = location.getQualifiedCoordinates().getLongitude();
latitude = location.getQualifiedCoordinates().getLatitude();
updateLocationScreen(latitude, longitude);
}
}
public void providerStateChanged(LocationProvider provider, int newState)
{
}
}
private void updateLocationScreen(final double latitude, final double longitude)
{
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
lat = latitude;
longt = longitude;
RichTextField txt=new RichTextField();
txt.setText("Long=="+longt);
RichTextField txt1=new RichTextField();
txt1.setText("lat=="+lat);
add(txt);
add(txt1);
// persistentLatitude.setContents(Double.toString(latitude));
// persistentLongitude.setContents(Double.toString(longitude));
}
});
}
I would like to check for both GPS and internet (Wifi,BES,GPRS/edge etc) and whichever connection is available, I would like to acquire coordinates through the available service.
The default GPS location in BB Simulators is set to a position in CANADA (Waterloo as far as I remember), that's why you are getting the coordinates of CANADA. You can change the GPS location from 'Simulate->GPS Location' in BB Simulator. This video from BB SupportForums may help you.
The following links may also be helpful:
For connectivity issues see this link