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
New Developer
Posts: 3
Registered: ‎11-21-2012
My Device: Blackberry 9300
My Carrier: 3

GPS LocationUpdated() skipping *Updated with code*

[ Edited ]

Hi,

I am creating an app that logs the users GPS data every second and have encountered a problem.

 

Firstly:

Blackberry JRE = 5.0.0

Debugging device = Blackberry 9300 (OS v6.0)

 

According to the api:

http://www.blackberry.com/developers/docs/4.5.0api/javax/microedition/location/LocationListener.html... javax.microedition.location.Location)

and

http://www.blackberry.com/developers/docs/4.5.0api/javax/microedition/location/LocationProvider.html... int, int, int)

 

I am using: 

LocationProvider.getInstance(new Criteria()).setLocationListener(new MyLocationListener(), 1,1, 1);

 

I should be able to get the location (if GPS lock) every second. Or a non-valid/null location every second if no GPS lock.

What I have found is that the location is only being provided every 1050 - 1250ms yet timestamped with the last location + 1000. Meaning that after some amount of time, it is "missing" a location. 

 

I have also tried Setting a location listener and then polling the LocationProvider for the LastKnownLocation every 400ms, see if it has changed, if so accept the new location. This is more reliable, however still misses out some data points.

 

I am running pretty low on ideas and if anyone has any insight, I would be very greatful

 

 it is more prominent when other things are happening, which in my app there are.

 Observe when the time jump 2 seconds this is in the sim, even worse on the phone.

 LocExample:

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 net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class LocExample extends MainScreen {

	/**
	 * Creates a new CheckMyDrive object
	 */
	public LocExample() {

		try {
			LocationProvider.getInstance(new Criteria()).setLocationListener(
					new MyLocationListener(), 1, 1, 1);
		} catch (LocationException e) {
			System.out.println(e.getMessage());
		}

	}

	private class MyLocationListener implements LocationListener {
		public void locationUpdated(LocationProvider provider, Location location) {
			if (location != null && location.isValid()) {
				long time = location.getTimestamp();
				time /= 1000;
				time %= 60;
				System.out.println("+Time = " + time);
			} else {
				System.err.println("criccomini location not valid");
			}
		}

		public void providerStateChanged(LocationProvider provider, int newState) {
			// TODO: if provider was disabled, then disable reporting
		}
	}

}

 

 

Thanks,

Chris