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
stardomains
Posts: 186
Registered: ‎12-14-2009
My Device: Not Specified

Can't get simple single GPS location

I have a button listener that calls  handleGPS() when the user presses it. Then the app is supposed to get the coordinates and set a text field to those coordinates. But it is not working. What am I doing wrong here?

 

 public void  handleGPS()
      {
    	  
    	        Thread ttt = new Thread(new Runnable() {

    	            public void run() {
    	                
    	                try{
    	                	Criteria myCriteria = new Criteria();
    	    	            
    	    	            ((BlackBerryCriteria) myCriteria).setMode(GPSInfo.GPS_MODE_ASSIST);
    	    	            BlackBerryLocationProvider myProvider;
    	    	            myProvider  = (BlackBerryLocationProvider) LocationProvider.getInstance(myCriteria);
    	    	            BlackBerryLocation myLocation;
    	    	            myLocation = (BlackBerryLocation) myProvider.getLocation(300);
    	    	            double lat;
							double lon;
    	    	            float alt;
    	    	            lat = myLocation.getQualifiedCoordinates().getLatitude();
    	    	            lon = myLocation.getQualifiedCoordinates().getLongitude();
    	    	            alt = myLocation.getQualifiedCoordinates().getAltitude();
    	                  
    	                        String aString = Double.toString(lat);
    	                        asatrd.setText(aString);
    	                   
    	                }catch(Exception ex){
    	                    ex.printStackTrace();
    	                    System.err.println(ex.toString());
    	                }
    	            }
    	        });
    	        
    	        ttt.run();

    	  }

 

FieldChangeListener funko = new FieldChangeListener()
      {
      public void fieldChanged(Field field, int context)
      {
    	  handleGPS();

}};

 

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Can't get simple single GPS location

"not working" covers quite a bit of ground. Exactly what issues are you seeing? Are you getting an exception? Have you read the GPS and Maps documentation?

 

You don't mention what carrier you are on - this could be an issue with network-assist mode since not all networks support this mode.