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: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: Getting coordinates from GPS

What are you doing with this GPS information? Do you need a real-time display of the information? At a 5-minute gather rate, I rather doubt that. I don't see why you'd need LocationListener at all if all you're doing is getting the coordinates.According to the Developer Videos on Advanced GPS Usage, the first autonomous fix is what takes time. Every subsequent fix will have pre-emptive satelite data already, and will not require a long period of time to re-acquire the fix. I've tested this on my Bold and it seems to hold true -- I manually got my current position using BlackBerry maps every few minutes and only the first fix took more than a few seconds.

 

Consider the following... (The variable GPS is a LocationProvider with the criteria for an autonomous fix)

 

      //Fetch location
      Location location = GPS.getLocation (2000);
      
      //Get the position of the current location
      QualifiedCoordinates current = location.getQualifiedCoordinates ();

     
      double lat = current.getLatitude ();
      double lon = current.getLongitude ();

 

-------------------------------------------------------

 

As you can see, I didn't need a LocationListener at all, and these two variables now contain accurate (according to the simulator) GPS coordinates to do with what I will. I won't go into the spcifics of my application, but I basically have a background Thread that wakes up periodically to start a Thread that eventually results in gathering said GPS information.

 

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: Getting coordinates from GPS

@ydaraishy - Thanks!

 

@DAguilina

I need to log the coordinates at the given time. The interval is variable depending on the configuration. So that's the reason why i added a listener just to keep it hot. I'm not sure if the first fix is the only one that takes time. Because if your gps hardware gets cold after a several minutes of non-activity from your gps hardware, it will automatically get cold. Then by the time you retrieved the coordinates, it will again require you some time to get a fix. 

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: Getting coordinates from GPS

Do you know exactly how long it takes to go from "hot" to "cold"? You said "several minutes", which could mean that listening every say 3 minutes wouldn't allow the GPS to cool down anyway.

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: Getting coordinates from GPS

I'm not really sure how long it takes to go from hot to cold.  But yes, maybe 3 minutes wouldn't cool down the GPS, but how about 30mins? or even an hour? The interval is configurable. Which can be even every 2hours or more. Smiley Happy

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: Getting coordinates from GPS

If you're checking every 30 minutes, then there's no reason to keep the chip hot lol. In my program the interval is about 3 minutes (though eventually this will be variable), so I'm not sure if I need keep the chip hot manually. Implementing this would require a bit of an overhaul, as well as a buttload more error handling XD If I could avoid putting in a locationListener, etc, then my life becomes much easier. Hence the curiosity Smiley Tongue

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Developer
Posts: 132
Registered: ‎02-11-2009
My Device: Not Specified

Re: Getting coordinates from GPS

I would suggest using the LocationListener interface. If you find it hard to pick an update interval, you may specify -1 and let the hardware update at its "native" rate (which is a bit different for every phone). Every time the locationUpdated event fires, keep the coords. And every 5 minutes send the last coords you got.

 

 

Highlighted
Regular Contributor
Posts: 58
Registered: ‎03-23-2011
My Device: 9800
My Carrier: programmer

Re: Getting coordinates from GPS

Hi DAlquilina,

how did you do it without LocationListener and with just a background thread?

no idea, I've been trying but I don't achieve. Could you show the code?

Thanks,

Alfred