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 Contributor
Posts: 4
Registered: ‎07-02-2012
My Device: Blackberry 9500
My Carrier: Vodafone
Accepted Solution

GPS work on simulator but not on phone

Hi

 

I have created a simple app which gets the GPS location of the device. The app works perfectly on the simulator but I get no GPS updates on the phone. I have been into options -> Device -> Location.Settings on the phone and can clearly see GPS updates are coming through. But the app says there are no vaild GPS being received.

 

I have tried it on BlackBerry 9800.. All I get on the phone is "Awaiting GPS update", which my app displays if no valid GPS fix is received.

 

Many thanks in advance.

 

Kevin

 

 

Criteria c= newCriteria();

 

c.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);

c.setVerticalAccuracy(Criteria.NO_REQUIREMENT);

c.setCostAllowed(true);

c.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);

 

LocationProvider lp;

try

{

lp = LocationProvider.getInstance (c);

if (lp != null)

{

  // lp.getLocation (timeout);

  lp.setLocationListener(newMyLocationListener(), -1, 1, 1);

}

else

{

Dialog.alert("Sorry - Your phone does not support GPS");

}

 

}

catch(Exception e)

{

System.

err.println(e.toString());

}

 

}

privateclass MyLocationListener implementsLocationListener

{

publicvoidlocationUpdated(LocationProvider provider, Location location)

{

if(location != null&& location.isValid())

{

QualifiedCoordinates qc = location.getQualifiedCoordinates();

try

{

String Lat = Double.toString (qc.getLatitude());

String Long = Double.toString (qc.getLongitude());

 

UpdateScreen ("Location Successfully Recording");

}

else

{

UpdateScreen ("Failed to update location");

}

}

catch(Exception e)

{

}

}

else

{

UpdateScreen ("Awaiting GPS update");

}

}

publicvoid providerStateChanged(LocationProvider provider, intnewState)

{

// TODO: if provider was disabled, then disable reporting

}

}

 

New Contributor
Posts: 4
Registered: ‎07-02-2012
My Device: Blackberry 9500
My Carrier: Vodafone

Re: GPS work on simulator but not on phone

Sorry forgot to add, I have tried it on an O2 and Vodafone network both give the same results.

Developer
Posts: 16,676
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: GPS work on simulator but not on phone

welcome to the support forums.
i would suggest to take care with the exceptions. empty catch blocks or sysouts may get lost, better to use a logger or print to sysout and debug.

also check the parameters when you register the listener, '1' may be too short for a real gps provider to answer, better go with -1 for starters to have the default behavior
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Contributor
Posts: 4
Registered: ‎07-02-2012
My Device: Blackberry 9500
My Carrier: Vodafone

Re: GPS work on simulator but not on phone

Thank you for your help. I have tried changing listener parameters to all default (-1) and to 60, -1, -1. Both failed to provide a valid GPS  locaton, but I can see in options -> Location Setting   the GPS location being updated. I have also tested the app standing outside my south facing front door with no success.

 

Developer
Posts: 19,628
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS work on simulator but not on phone

Try the sample programs you will find here:

 

http://supportforums.blackberry.com/t5/Java-Development/BBM-shareContent/m-p/1796237#M203486

 

or here:

 

http://supportforums.blackberry.com/t5/Java-Development/Simple-Location-API/ta-p/1145951

 

See if these work on device.  If they do, review the code contained and compare with yours.

New Contributor
Posts: 4
Registered: ‎07-02-2012
My Device: Blackberry 9500
My Carrier: Vodafone

Re: GPS work on simulator but not on phone

Thanks Peter. I changed from 60 to 90 seconds and now I am getting valid GPS fixes.

 

Many thanks