Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified
Accepted Solution

GPS Timed Out error when querying location

Hello everyone,

 

I have been working with GPS and maps on BlackBerry OS 5.0, and it has been frustrating to say the least.  I have everything working, however I am receiving a "GPS timed out" error whenever I try to query my location.  I receive this error only on an actual device, not on the simulator.  This happens for both MapField and the native BlackBerry Map.

 

Essentially, what I am doing is looking for the current coordinates via GPS, translating those coordinates into an address via reverseGeocoding (a separate thread), and then using that zip code to find and plot locations from a web service.  The web service is working correctly, it is the GPS that is the problem.

 

I'd appreciate it if somebody could take a look at my code and see if anything sticks out.  Here is my LocationHandler (implementing LocationListener):

 

 

import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import javax.microedition.location.QualifiedCoordinates;
import com.usps.mobile.blackberry.Constants;
import com.usps.mobile.blackberry.Inform;
import com.usps.mobile.blackberry.interfaces.ScreenLocation;

public class LocationHandler extends Thread implements LocationListener {
	private ScreenLocation screen;
	private boolean periodicUpdates;

	public LocationHandler(ScreenLocation screen, boolean update) {
		this.screen = screen;
		this.periodicUpdates = update;
	}

	public void locationUpdated(LocationProvider provider, Location location) {
		QualifiedCoordinates qualifiedCoordinates = location
				.getQualifiedCoordinates();

		int longitude = (int) (qualifiedCoordinates.getLongitude() * 1000000);
		int latitude = (int) (qualifiedCoordinates.getLatitude() * 1000000);
		new myReverseGeocode(longitude, latitude, screen);
	}

	public void providerStateChanged(LocationProvider provider, int newState) {
		// So far, nothing for this
	}

	/**
	 * The thread
	 */
	public void run() {
		Criteria criteria = new Criteria();
		criteria.setVerticalAccuracy(Constants.DEFAULT_VERTICAL_ACCURACY);
		criteria.setHorizontalAccuracy(Constants.DEFAULT_HORIZONTAL_ACCURACY);
		criteria.setCostAllowed(true);
		criteria
				.setPreferredPowerConsumption(Constants.DEFAULT_GPS_POWER_CONSUMPTION);

		try {
			LocationProvider provider = LocationProvider.getInstance(criteria);
			Location location = provider.getLocation(-1);

			locationUpdated(provider, location);
			if (periodicUpdates) {
				// Update every 1 minute
				provider.setLocationListener(this, 60, -1, 10);
			}
		} catch (final LocationException e) {

			Inform.inform(e.getMessage());

			screen.setLocation(Constants.DEFAULT_LONGITUDE,
					Constants.DEFAULT_LATITUDE);
		} catch (final InterruptedException e) {

			Inform.inform(e.getMessage());

			screen.setLocation(Constants.DEFAULT_LONGITUDE,
					Constants.DEFAULT_LATITUDE);
		}
	}

}

 

The setLocation method in my main screen:

 

 

public void setLocation(int longitude, int latitude, AddressInfo addrInfo) {
		synchronized (UiApplication.getEventLock()) {
			mapField.moveTo(latitude, longitude);

			mapField.setZoom(Math.max(mapField.getZoom() - 1, mapField
					.getMinZoom()));

			doWebService(addrInfo.getField(AddressInfo.POSTAL_CODE));
		}
	}

 

Like I said, reverseGeocode() is on its own thread, and it is returning correct information.

 

Thanks!

 

 

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: GPS Timed Out error when querying location

Also, I am positive that my device GPS is enabled. It seems like the device just instantly says that the GPS is timed out.

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: GPS Timed Out error when querying location

[ Edited ]

What carrier?  What device?  What GPS mode are you trying to use?

 

Have you looked at this: http://supportforums.blackberry.com/t5/Java-Development/Location-APIs-Start-to-finish/ta-p/571949 ?

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: GPS Timed Out error when querying location

I am using the BlackBerry Tour 9630 on Verizon Wireless, and the phone is set to "Location On".  My code is set to use Assisted and Unassisted mode with:

 

 

Criteria criteria = new Criteria();
		
// Set to 50
criteria.setVerticalAccuracy(Constants.DEFAULT_VERTICAL_ACCURACY);
		
// Set to 50
criteria.setHorizontalAccuracy(Constants.DEFAULT_HORIZONTAL_ACCURACY);

criteria.setCostAllowed(true);
	
// Set to High	
criteria.setPreferredPowerConsumption(Constants.DEFAULT_GPS_POWER_CONSUMPTION);

 

 

 

Developer
Posts: 100
Registered: ‎04-07-2009
My Device: Not Specified

Re: GPS Timed Out error when querying location

This is not the direct answer, but are you sure that you need the lat/lon values in a million degrees? MapField uses 100.000 degrees.

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: GPS Timed Out error when querying location

[ Edited ]

On verizon.

 

You will not be able to get assisted without PDE access.   The criteria you showed, does not map to autonomous.

 

Autonomous can take a while to get and pretty much has to have clear view of the sky for decent performance.

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: GPS Timed Out error when querying location

Interesting. I had no idea about that. Thanks for clearing that up!

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: GPS Timed Out error when querying location

The issue was actually the one reported in the post below, however I didn't notice the extra 0's on my lat/lon's.  Thanks for noticing that!