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
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Best way to retrieve GPS Location

Hey fellows, I need your help.

 

I've done one or two applications that use GPS until now. All of them work, but they're a little inconstant in this matter. 

 

Now I'm working on a new one and I'm having troubles to make it work in the costumer's BB.

 

I am testing in a Curve 8310, which works quite well, and the custumer is trying in a Curve and a Bold devices (don't know exactly which model). He uses other applications like GoogleMaps (I dont have a clue of how do they get the user location so well) and foursquare, and they work well with the GPS.

 

I'm aiming for the 4.2.1 OS version.

 

The method I am using to retrieve the Location is the following:

 

public static void getCoordinates() {
	new Thread() {
		public void run() {
			try {
                                LocationProvider locationProvider = LocationProvider.getInstance(null);
				Location location = locationProvider.getLocation(90);
				longitude = location.getQualifiedCoordinates()			.getLongitude();
					latitude = location.getQualifiedCoordinates().getLatitude();
			} catch (Exception e) {
			    // handle exception
			}
		}
	}.start();
}

 

It's quite simple and I didn't find nothing much different from this anywhere else in my researchs.

 

I also tried to instantiate the LocationProvider with a Criteria but I think that doesn't makes much difference, since all I need is basic stuff, and most of it are already set by default.

 

Is there anything else I could do?

 

I read about the many types of location retrieval that exists as PDE, Cellsite, GPS, etc. But I don't care, I just want the lat and long, shouldn't it work that simple way, doesn't matter how? Or is this GPS thing something like the HttpConnection **bleep**, that we need to do everything by ourselves with a lot of workarounds? 

 

I would really appreciate your help.

 

Thank you.

 

Rgs,

Dan

Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: Best way to retrieve GPS Location

Now something strange happened.

 

I couldn't get my location through my application, then I opened the Blackberry Maps which found my location very fast. I went back to my application and voila, it started to get my location pretty fast also.

 

Was that a coincidence? Or the fact that I retrieved my location using the Blackberry Maps first trigered something that would make my app start working?

 

Anyone?

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Best way to retrieve GPS Location

Google Maps uses Google's cell tower location database for a "first fix" - it is fast but not accurate.

 

You are requesting the "default"provider, which is likley going to be stand-alone mode on the devices you are looking at. This will take a long time (more than 90 seconds) if you are outside with a clear view to the sky, and it won't work at all if you are in a building.

 

Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: Best way to retrieve GPS Location

Thank you very much for your answer RexDoug!

 

But what whould be the best approach for my case then?

 

I actually don't need accuracy for the apps I'm working on.What about the Blackberry Maps application? It is fast enough. Is it possible to do something like that?

 

Thanks!

 

Rgs,

Dan

Contributor
AMZDeCoder
Posts: 12
Registered: ‎10-29-2011
My Device: 9300 Curve 3G

Re: Best way to retrieve GPS Location

Any updates on this thread.. I am facing a similar issue.

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Best way to retrieve GPS Location

There is no simple answer to "why doesn't my GPS code work".

 

You'll need to be specific about the type of GPS method you are using, the carrier, and the device.

 

Also as stated above, if you are using autonomous mode, this won't work indoors.

 

If you are using network-assisted mode, you need to be cognizent of the support (or lack thereof) on your specific network.

 

Have you read all of the KB articles on the subject?