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
Raiden
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified
Accepted Solution

How to know GPS Listener doesn't work

Hello guys'

 

I have some problems. I am using GPS Listener (LocationListener). But it works not good. 

Sometimes it can't get current location. 

 

You can see my code related GPS. It is used for to start or stop LocationListener. 

 

private class GpsListener implements LocationListener {

LocationProvider lp;

 

public GpsListener() {
lp = null;
}

public boolean isConnected() {
return (lp != null);
}

public void start() {
if (lp == null) {
try {
lp = LocationProvider.getInstance(null);
if(lp != null) {
lp.setLocationListener(this, _getLocationInterval, _getLocationTimeout, -1);
}
} catch(LocationException e) {

 

}
}
}

public void stop() {
if (lp != null) {
lp.reset();
lp.setLocationListener(null, -1, -1, -1);
lp = null;
}
}

public void locationUpdated(LocationProvider provider, Location location) {
if(location.isValid()) {

  //TODO something

}
}

public void providerStateChanged(LocationProvider provider, int newState) {
//Nothing
}
}

 

The thing that I want to know is HOW TO KNOW DON'T WORK GPS LOCATION LISTENER 

 

if you have a some idea, plz help me'

 

Tnx again'

 

Please use plain text.
Developer
anildeveloper
Posts: 33
Registered: ‎07-16-2008
My Device: Not Specified

Re: How to know GPS Listener doesn't work

I recommend to make a try + catch- statement and record everything toPersistentStore; then it is easy to find out;

public void locationUpdated(LocationProvider provider, Location location) {
StringBuffer b = new StringBuffer();
double longitude = 0.0d;
double latitude = 0.0d;

float haccuracy = 0.0f;
float vaccuracy = 0.0f;

float speed = 0.0f;
long timeStamp = 0;

try {
if(! location.isValid()) throw new Exception ("location not valid");
QualifiedCoordinates c = null;
c = location.getQualifiedCoordinates();
longitude = c.getLongitude();
b.append("long ok: ").append(longitude).append(";");
latitude = c.getLatitude();
b.append("lat ok: ").append(latitude).append(";");
haccuracy = c.getHorizontalAccuracy();
b.append("hac ok: ").append(haccuracy).append(";");
vaccuracy = c.getVerticalAccuracy();
b.append("vac ok: ").append(vaccuracy).append(";");
timeStampGps = location.getTimestamp();
b.append("timeStampGps ok: ").append(timeStampGps).append(";");

speed = location.getSpeed();
if (speed == Float.NaN) b.append("speed ok: NOT A NUMBER!;");
else b.append("speed ok: ").append(speed).append(";");
}
catch (Exception e){
String errorText = e.getMessage() + " " + b.toString();
// now write errorText to PersistentStore
}
}

 

 

Please use plain text.
Developer
Raiden
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: How to know GPS Listener doesn't work

Tnx' I got it'
Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to know GPS Listener doesn't work

Following is taken from a similar thread in the old forum, kudos to gmay (Gordon) from Rim.  I have found the KB article extremely useful.  Tracking is OK, but as the article points out, that doesn't tell you when you need to do a reset. 

 

The providerStateChanged(LocationProvider, int) method is called when the state of the LocationProvider changes between Available, Out of Service, and Temporarily Unavailable. Definitions of each state can be found within the Javadocs.

Also see the How To - Detect when GPS is no longer available and when to reset the LocationProvider (DB-00577):
http://tinyurl.com/23x4mo

or

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800703/How_To_...

Please use plain text.
New Developer
jigar_15in
Posts: 7
Registered: ‎10-03-2008
My Device: Not Specified

Re: How to know GPS Listener doesn't work

Thanks it works for me also ! i guess
Please use plain text.