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: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

GPS problem

[ Edited ]

I want to retrieve longitude and latitude using GPS. I have written following code in a thread.

				try
				{
					BlackBerryCriteria blackBerryCriteria = new BlackBerryCriteria();

					if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CELLSITE)) 
					{
						blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CELLSITE);
					}
					else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASSIST)) 
					{
						blackBerryCriteria.setMode(GPSInfo.GPS_MODE_ASSIST);
					}
					else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUTONOMOUS)) 
					{
						blackBerryCriteria.setMode(GPSInfo.GPS_MODE_AUTONOMOUS);
					}
					else 
					{
						blackBerryCriteria.setCostAllowed(false);
						blackBerryCriteria.setPreferredPowerConsumption(BlackBerryCriteria.POWER_USAGE_LOW);
					}
					try 
					{
						BlackBerryLocationProvider blackBerryLocationProvider = (BlackBerryLocationProvider) BlackBerryLocationProvider.getInstance(blackBerryCriteria);
						Location blackBerryLocation = (Location) blackBerryLocationProvider.getLocation(60);

						QualifiedCoordinates qualifiedCoordinates = blackBerryLocation.getQualifiedCoordinates();
						final double lat;
						final double lng;
						lat = qualifiedCoordinates.getLatitude();
						lng = qualifiedCoordinates.getLongitude();
						UiApplication.getUiApplication().invokeLater( new Runnable() 
						{
							public void run()
							{
								Dialog.alert("Lat: "+lat+" Lng: "+lng);
							}
						});
					}
					catch(final Exception e)
					{
						UiApplication.getUiApplication().invokeLater( new Runnable() 
						{
							public void run()
							{
								Dialog.alert(e.toString());
							}
						});
						System.out.println("Error in location :"+e.toString());
						System.out.println("Error in location :"+e.getMessage());
					}
				}
				
				catch (final Exception e) 
				{
					UiApplication.getUiApplication().invokeLater( new Runnable() 
					{
						public void run()
						{
							Dialog.alert(e.toString());
						}
					});
					System.out.print(e.toString());
				}
			

 In case of Simulator:

 Above code runs fine in OS 7. But in OS 5 ,BlackBerryLocationProvider returns null. In OS 6 i am getting LocationException: Timed out while waiting for location.

 

In case of actual device:

Above code runs fine in os 5 and 6 but get nothing in remaining one(Not even any exception)

 

How should i fix this? Please help.

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: GPS problem

Can someone please reply? I am working on above code. and now its only not working on device having OS 7.1. Please someone help,
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS problem

Can I suggest that you review the following, that provide the best information and samples I have seen for GPS and related Location Services:

 

http://supportforums.blackberry.com/t5/Java-Development/Location-APIs-Start-to-finish/ta-p/571949

 

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

 

 

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: GPS problem

I have checked it already
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS problem

OK, well I guess the obvious question is why aren't you just using SimpleLocationAPI to save writing your own?

 

That said, I don't understand this given your code:

"get nothing in remaining one(Not even any exception)"

 

I would expect a Dialog.  So perhaps there is a more fundamental problem here regarding how you start this processing.  When is it started?  How is it started?

 

The other thing I would find useful is if you could debug this code, step through it, and tell us what happens in particular circumstances.  You can do this on device and it would probably be very useful for you to do this.

 

Be aware that you are extremely unlike to get a GPS fix in 60 seconds, or get a GPS fix at all for a phone that is sitting on your desk - it needs to see sky!