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
Developer
Posts: 79
Registered: ‎11-10-2009
My Device: Torch 9800
My Carrier: AT&T
Accepted Solution

GPS returns 0.0 for speed and longitude

I keep getting 0.0 for both speed (except invalid NaN) and longitude.  Latitude and course return a valid number. This is on a Torch 9810 OS7 but the app is set for OS6.  Watching in the attached console through Eclipse,

 

 

public class LocationListener implements javax.microedition.location.LocationListener{

	private static long lastFix = 0l;
	private static Object lock = new Object();
	
	public void locationUpdated(LocationProvider provider, Location location) {
		try {
			BlackBerryLocation loc = (BlackBerryLocation) location;
	    	double longitude = 0d;
	    	double latitude = 0d;
	    	if (loc.getQualifiedCoordinates() != null) {
		    	longitude = loc.getQualifiedCoordinates().getLongitude();
		    	latitude = loc.getQualifiedCoordinates().getLatitude();
	    	}
	    	float speed = loc.getSpeed();
	    	float course = loc.getCourse();
	    	setLastFix(loc.getTimestamp());
	    	GPSLocation gps = new GPSLocation(longitude, latitude, speed, course, (loc.getTimestamp() == 0l ? System.currentTimeMillis() : loc.getTimestamp()));
			gps.setValid(loc.isValid());
	    	gps.setStatus(loc.getStatus());
	    	gps.setError(loc.getError());
			gps.print();
	    	App.addToPool(gps);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void providerStateChanged(LocationProvider provider, int newState) {
		if (newState == LocationProvider.TEMPORARILY_UNAVAILABLE) {
			provider.reset();
			provider.setLocationListener(null, 0, 0, 0);
		}
		App.setupGpsPolling();
	}

	public static void setLastFix(long lastFix) {
		synchronized (lock) {
			if (lastFix != 0l)
				LocationListener.lastFix = lastFix;
		}
	}

	public static long getLastFix() {
		synchronized (lock) {
			return lastFix;
		}
	}
	
}


public class GPSLocation {
	......
	public void print() {
		StringBuffer sb = new StringBuffer();
		sb.append("longitude: " + getLongitude()).append("\r\n");
		sb.append("latitude: " + getLatitude()).append("\r\n");
		sb.append("speed: " + getSpeed()).append("\r\n");
		sb.append("course: " + getCourse()).append("\r\n");
		sb.append("ts: " + getTimestamp()).append("\r\n");
		sb.append("stat: " + getStatus()).append("\r\n");
		sb.append("err: " + getError()).append("\r\n");
		sb.append("valid: " + isValid()).append("\r\n");
		System.out.println(sb.toString());
	}
	......
}

 

Developer
Posts: 79
Registered: ‎11-10-2009
My Device: Torch 9800
My Carrier: AT&T

Re: GPS returns 0.0 for speed and longitude

Not sure what I did, but speed seems to be working now. Longitude is still always 0.0
Highlighted
Developer
Posts: 79
Registered: ‎11-10-2009
My Device: Torch 9800
My Carrier: AT&T

Re: GPS returns 0.0 for speed and longitude

I don't get it.  Doing it this way works.

 

	    	QualifiedCoordinates coor = location.getQualifiedCoordinates();
	    	if (coor != null) {
    			longitude = coor.getLongitude();
    			latitude = coor.getLatitude();
                }