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: 75
Registered: ‎07-22-2011
My Device: curve 9300
My Carrier: New member
Accepted Solution

GPS not working in blackberry device through java coding

[ Edited ]

Hi frnds,

 

I need to get the current GPS location through my java program. Im using the following code. This code is working for simulator. but not in device.. In my device GPS showing the proper location. But through this coding im not able to get. Please help me.. Its urgent. Thanks in advance 

 

 public class gps extends MainScreen { 

  static GPSThread gpsThread; 

  static double latitude; 

  static double longitude;   


    public gps()    {     

  gpsThread = new GPSThread();        gpsThread.start(); 

  }
    private static class GPSThread extends Thread    {     

  public void run()        {           

Criteria myCriteria = new Criteria();

myCriteria.setCostAllowed(false);
            try{       

        LocationProvider myLocationProvider =  LocationProvider.getInstance(myCriteria);
               try {

                    Location myLocation = myLocationProvider.getLocation(300);
                      latitude   = myLocation.getQualifiedCoordinates().getLatitude()

                 longitude  = myLocation.getQualifiedCoordinates().getLongitude();       

                         StringBuffer sb = new StringBuffer();            

     sb.append(latitude);  

              sb.append(":");      

             sb.append(longitude);                

                String msg = sb.toString();  

                showResults(msg);           

   }           

   catch ( InterruptedException iex )     

         {                    return;                }         

     catch ( LocationException lex )                {                    return;                }     

      }            catch ( LocationException lex )            {                return;            }
            return;     

  }

    } 

 

private static void showResults(final String msg){

 Application.getApplication().invokeLater(new Runnable()    {

       public void run()        {       

 

 Dialog.alert(""+msg);          

    }  

 });

    }

}

 

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

Re: GPS not working in blackberry device through java coding

Program is not visible at my end.

Developer
Posts: 75
Registered: ‎07-22-2011
My Device: curve 9300
My Carrier: New member

Re: GPS not working in blackberry device through java coding

Can you please check now

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

Re: GPS not working in blackberry device through java coding

I think timeout should be increased to few minutes or so. The reason is programmatically using the GPS takes loger as compared to manual refresh in device.
Developer
Posts: 75
Registered: ‎07-22-2011
My Device: curve 9300
My Carrier: New member

Re: GPS not working in blackberry device through java coding

Hi swap_chau,

Thanks for your response.. i increased the time....but no luck...hepl me.

 

 

Thanks,

Karthika J

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

Re: GPS not working in blackberry device through java coding

Hi I used the following code with timeout set to 30 minutes, but you can keep it low up to 5 minutes.

try {
// select the location mode
criteria = new BlackBerryCriteria(_locationMode);
} catch (UnsupportedOperationException e) {
handleFailure();
return;
}
try {
_provider = (BlackBerryLocationProvider) BlackBerryLocationProvider
.getInstance(criteria);

} catch (LocationException e) {
handleFailure();
return;
}
try {
// get location
blackBerryLocation = (BlackBerryLocation) _provider
.getLocation(TIME_OUT);
_longitude = blackBerryLocation.getQualifiedCoordinates()
.getLongitude();
_latitude = blackBerryLocation.getQualifiedCoordinates()
.getLatitude();

} catch (Exception e) {
handleFailure();
return;
}
Developer
Posts: 75
Registered: ‎07-22-2011
My Device: curve 9300
My Carrier: New member

Re: GPS not working in blackberry device through java coding

Hi swap_chau,

 

Thanks for your response.i checked the timeout.. i kept the timeout as 10 mins... i set the location mode  as "GPSInfo.GPS_MODE_ASSIST"... but no luck..

 

 

Thanks,

Karthika J

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

Re: GPS not working in blackberry device through java coding

Try changing LocationProvider to BlackBerryLocationProvider. Use the above mentioned code and test it. It works for me. You can later change it to suite your requirement.
Developer
Posts: 75
Registered: ‎07-22-2011
My Device: curve 9300
My Carrier: New member

Re: GPS not working in blackberry device through java coding

[ Edited ]

Thanks for your response...I changed as you said...Its working in simulator..not in device..i dont know why its not working in device...i checked device settings...its fine only..but  :smileysad:    !!!!!!!!!!!!!!

 

 

Thanks,

Karthika J

 

Developer
Posts: 75
Registered: ‎07-22-2011
My Device: curve 9300
My Carrier: New member

Re: GPS not working in blackberry device through java coding

Hi please help me regarding GPS

 

 

Thanks,

Karthika J