0

I am using following code to get current latitude and longitude. But none of the toasts are displayed.

public void onCreate(Bundle savedInstanceState) {  

                super.onCreate(savedInstanceState);  

                setContentView(R.layout.main);  


                /* Use the LocationManager class to obtain GPS locations */    
                LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);   
                LocationListener mlocListener = new MyLocationListener();    
                mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);   
                 }     

             /* Class My Location Listener */    
            public class MyLocationListener implements LocationListener     {   
                @Override       
                public void onLocationChanged(Location loc)       {  
                    Log.i("","loccccccccccc");  
                    loc.getLatitude();        
                    loc.getLongitude();     
                    String Text = "My current location is: " +         "Latitud = " + loc.getLatitude() +         "Longitud = " + loc.getLongitude();    
                     Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_LONG).show();    
                     }        

                @Override    
                public void onProviderDisabled(String provider)       {    
                    Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();     
                    }         

                @Override     
                 public void onProviderEnabled(String provider)       {     
                    Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();   
                    }        

                 @Override        
                 public void onStatusChanged(String provider, int status, Bundle extras)       {     


                }        }
              } 

used all the permissions:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />  

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  

    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />  

    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />  

    <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />  

    <uses-permission android:name="android.permission.INTERNET" />  

Thanks for the help in advance
Sneha

Sandip Jadhav
  • 7,377
  • 8
  • 44
  • 76
Smitha
  • 6,110
  • 24
  • 90
  • 161

3 Answers3

0

GPS_PROVIDER is slow when compared to The NETWORK_PROVIDER.And in room it may not work.Switch on the GPS if you want to use GPS_PROVIDER. or else use NETWORK_PROVIDER.

Go through this

Note:Network_provider is not so accurate compared to the GPS_Provider.. But it is fast..

See this link also

Community
  • 1
  • 1
Abhi
  • 8,935
  • 7
  • 37
  • 60
0

GPS doesn't work in indoor mode..depending upon the place..It works perfectly on outdoor mode..So check it out outside..

Hulk
  • 2,565
  • 16
  • 24
0

@Sneha --

1) is this line printed Log.i("","loccccccccccc");

2) Check this

3) try to use criteria

4) Test this on mobile (Device) & also test it outside as GPS doesn't work inside.

Sandip Jadhav
  • 7,377
  • 8
  • 44
  • 76