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 Developer
alanbirtles
Posts: 5
Registered: ‎08-18-2008
My Device: Not Specified

LocationProvider problems

I am using the following code to get a GPS location:

 

while (true)

{

              if (locationProvider == null)        
                {
                    System.out.println("GPS: Creating location provider");
                    Criteria criteria = new Criteria();
                    criteria.setHorizontalAccuracy(REQUIRED_ACCURACY);
                    locationProvider = LocationProvider.getInstance(criteria);
                }
                boolean positionFound = false;
                if (locationProvider != null)
                {
                    System.out.println("GPS: getting location");
                    Location l = locationProvider.getLocation(TIMEOUT_SECONDS);

                    if (l != null)
                    {
                        System.out.println("GPS: location found");
                        Coordinates c = l.getQualifiedCoordinates();

                        if (c != null)
                        {
                            positionFound = true;
                            System.out.println("GPS: Got position: "+c.getLatitude()+", " + c.getLongitude());                           
                            recorder.gpsPositionChanged(new GpsPosition(c.getLatitude(), c.getLongitude()));
                        }
                    }
                }
                if (!positionFound)
                {
                    System.out.println("No position available");
                    GpsPosition lastPosition = recorder.getLastPosition();
                    if (lastPosition!=null)
                    {
                        System.out.println("Last position: "+lastPosition);
                    }
                }

}

 

I am testing the code on a blackberry curve 8320. When the code starts a dialog is shown asking if the application has permission to use gps. If the "Dont show this again" box is checked and the user selects yes then a runtime exception is thrown (with no message or details). If the box is not checked then the operation times out (as expected as I have no gps signal). Also if the user selects no then a security exception is thrown (again as expected).

Any ideas?

Please use plain text.
Administrator
MSohm
Posts: 14,569
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: LocationProvider problems

What BlackBerry handheld software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.  Are you seeing this in version 4.5.0?  What are the toString details of the exception?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
alanbirtles
Posts: 5
Registered: ‎08-18-2008
My Device: Not Specified

Re: LocationProvider problems

i am using 4.2.2.194 which is the latest (in fact later) version available for the 8320 according to your support pages.

As posted above there are no details for the exception just "java.lang.RuntimeException"

Please use plain text.
Administrator
MSohm
Posts: 14,569
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: LocationProvider problems

I haven't been able to reproduce this.  Are you testing in a MIDlet or BlackBerry CLDC application?  Can you provide a larger code sample?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
alanbirtles
Posts: 5
Registered: ‎08-18-2008
My Device: Not Specified

Re: LocationProvider problems

its in a midlet. Other than running the above code as a background thread the application doesn't do much. Checking the state of the gps before asking for a location seems to prevent the problem
Please use plain text.