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
Contributor
Posts: 25
Registered: ‎02-15-2012
My Device: Storm
My Carrier: Vodacom
Accepted Solution

GPS Coordinates = 0.0

Criteria criteria = new Criteria();
        criteria.setVerticalAccuracy(50);
        criteria.setHorizontalAccuracy(50);
        criteria.setCostAllowed(true);
        criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_MEDIUM);
        try {
        LocationProvider provider =
        LocationProvider.getInstance(criteria);
        Location location = provider.getLocation(-1);
        QualifiedCoordinates qualifiedCoordinates = location.getQualifiedCoordinates();
        latitude = qualifiedCoordinates.getLatitude();
        longitude = qualifiedCoordinates.getLongitude();
        
        } catch (LocationException e) {

        } catch (InterruptedException e) {

        }

 

and I set a location on the Emulator but it always comes back as 0.0

have I missed something?

Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: GPS Coordinates = 0.0

Can you try it without using criteria? I used BlackberryLocationProvider to retrieve the location, and it works properly.
Contributor
Posts: 25
Registered: ‎02-15-2012
My Device: Storm
My Carrier: Vodacom

Re: GPS Coordinates = 0.0

I tried without the criteria and it still isnt working for me...mabye im doing something wrong with the emulator?

Is there a specific time u ment to add the co-ordinates?

Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: GPS Coordinates = 0.0

I used the following code:

 

criteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_AUTONOMOUS)

_provider = (BlackBerryLocationProvider) BlackBerryLocationProvider
.getInstance(criteria);
 if (_provider == null) {// failed

failed(); 

} else{

blackBerryLocation = (BlackBerryLocation) _provider
 .getLocation(30*60);
_longitude = blackBerryLocation.getQualifiedCoordinates()
.getLongitude();

_latitude = blackBerryLocation.getQualifiedCoordinates()
.getLatitude(); 

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

Re: GPS Coordinates = 0.0

Can we have the SImulator and OS Levels involved here?

 

Remember with the Simulator you you need to Edit and Save the change you make.  Also it doesn't appear, on some SImulators, that this sticks between use of the Simulator. 

 

Can you re post the code you are now using?

 

Also remember that you can't do this on the Event Thread.

 

There is alot more information about GPS here:

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

 

Also do a search for SimpleLocationAPI.  It may do what you want a lot easier. 

 

 

Contributor
Posts: 25
Registered: ‎02-15-2012
My Device: Storm
My Carrier: Vodacom

Re: GPS Coordinates = 0.0

[ Edited ]

Criteria criteria = new Criteria(); criteria.setCostAllowed(false); try { LocationProvider provider = LocationProvider.getInstance(criteria); Location location = provider.getLocation(-1); latitude = location.getQualifiedCoordinates().getLatitude(); longitude = location.getQualifiedCoordinates().getLongitude(); } catch (LocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }

 

OS 7.1 and Blackberry 9900 Simulator in eclipse

still giving me o.o

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

Re: GPS Coordinates = 0.0

Sorry I can't replicate that environment myself, hopefully someone else can.

 

If you are using that level of OS, then you need to be aware that it will only run on OS 7.1 devices.  You might want to use a previous level of the JDE to get  support of older devices. 

 

Criteria can be used in older devices,  With newer devices you get the BlackBerry prefixed GPS classes that give you more flexibility.

 

Anyway, here is a method I use to generate criteria that I use for GPS locations:

 

        public static Criteria getStandardGPSCriteria() {
                Criteria cr = new Criteria();
                try {
                        cr.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
                        cr.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
                        cr.setCostAllowed(false);
                        cr.setPreferredPowerConsumption(Criteria.NO_REQUIREMENT);
                        cr.setPreferredResponseTime(180000);
                } catch (Exception e) {
                        System.out.println("Error creating GPS Criteria: " + e.toString());
                        cr = null;
                }
                return cr;
        }

Contributor
Posts: 25
Registered: ‎02-15-2012
My Device: Storm
My Carrier: Vodacom

Re: GPS Coordinates = 0.0

ok what level would you sugest? and would this code work for it?

 

Contributor
Posts: 25
Registered: ‎02-15-2012
My Device: Storm
My Carrier: Vodacom

Re: GPS Coordinates = 0.0

Thanks Peter, u helped me figure it out Smiley Happy

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

Re: GPS Coordinates = 0.0

Out of curiosity, what was the problem?

 

Re OS Levels, I am generally targeting OS 5.