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
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

problem with gps

hello,

 

i make appliaction for getting current position,so i use location provider and and get latitude and longitude which values are 0.0

 

i do not have device.so how i can know that this code is working or not.

 

please reply .

Developer
Posts: 133
Registered: ‎04-30-2010
My Device: Curve 8520
My Carrier: T-Mobile

Re: problem with gps

When testing on the Simulator you can use the menu option: Simulate->GPS Location

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

Re: problem with gps

Once you have tested various locations as suggested by the previous poster, I strongly recommend that you get a real device and test your code in it.  Real GPS does not behave in the same way as the Simulator, primarily because of the issues with finding satellites (and so the delay in obtaining and accuracy of the data), but also because of the various criteria and types of fixes you can get.  So expect to spend some time debugging on a real device before you release your GPS code. 

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem with gps

[ Edited ]

thanks for reply.

 

i have one other issue.

 

when i put below code on buttonclick event ,it show me exception like

 

getLocation() method cannot be called from event thread

 

when i use this code without button click it work properly.

 

so please give me a solution.

 

 

code:

 

 locateme=new ButtonField("LOCATE ME",ButtonField.FIELD_LEFT);
         locateme.setChangeListener(new FieldChangeListener(){
         public void fieldChanged(Field field,int content)
         {
             if(field==locateme)
             {
                Location location;
                try
                {
                Criteria criteria = new Criteria();          
                criteria.setHorizontalAccuracy(50);          
                criteria.setVerticalAccuracy(50);
                criteria.setCostAllowed(true);
               
                LocationProvider lp = LocationProvider.getInstance(criteria);
                if(lp==null)
                {
                    Dialog.alert("GPS is not supported on this platform, exiting...");
                    System.exit(0);
                }
                location=lp.getLocation(90);
                if(location!=null && location.isValid())
                {
                        float heading=location.getCourse();
                        System.out.println("heading"+heading);
                        double longit = location.getQualifiedCoordinates().getLongitude();
                        double latit = location.getQualifiedCoordinates().getLatitude();
                        System.out.println("Lat && Long =====> "+longit+" && "+longit);
                        float speed=location.getSpeed();
                        System.out.println("speed"+speed);
                }
                }
                catch(Exception ex)
                {
                System.out.println("Exception in Gps===> "+ex.getMessage());
                }
            }
         }
         });
        add(locateme);

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

Re: problem with gps

Unsurprisingly, this is because you should not call getLocation from the Event Thread!  Smiley Happy

 

In fact, the general rule is that you do not call Blocking operations (like network processing, or Thread.sleep() for example) on the Event Thread.  The Event Thread is the Thread that processes the User interface processing, like Button Clicks.  You block that, your Application is dead as far as your user is concerned.  Not good.  So is not allowed. 

 

Search for references on the Event Thread for more information on that.

 

Review GPSDemo code for options to run your getLocation off the Event Thread. 

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem with gps

 

i show lots of example,but i do not get any idea,

i require to get latitude and longitude using GPS.

so what i do with above code.

please help me ,i waste my lots of time behind it. 

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

Re: problem with gps

I understand your requirement.

 

But to do this correctly, you need to understand better how to write code for the BlackBerry platform.  This will help you in this case and in the future. 

 

Here is a good place to start learning abut the Event Thread.

 

http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865

 

For more information on GPS in general, try this useful KB article

 

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