Problem to GPS in Android
<p>I am having problem to get GPS coordinate in my Android application.<br/>
When i am using <strong>LocationManager.NETWORK_PROVIDER</strong> then i am getting the GPS coordinates but when i am using <strong>gpsProvide=LocationManager.GPS_PROVIDER</strong> i do not get the GPS co-ordinate.<br/>
Then what should i use <strong>LocationManager.NETWORK_PROVIDER</strong> or <strong>LocationManager.GPS_PROVIDER</strong>?<br/> Can any body help</p>

<p>Here is my code:</p>

<pre><code>public class GPSLocation implements LocationListener 
{
    private double latitude = 0.0;
    private double longitude = 0.0;
    private boolean gpsSupported;
    LocationManager locationManager;
    String gpsProvide;
    public GPSLocation(LocationManager locManager)
    {

        gpsProvide=LocationManager.NETWORK_PROVIDER;
        gpsProvide=LocationManager.GPS_PROVIDER;
        locationManager = locManager;
        locationManager.requestLocationUpdates(gpsProvide, 0, 0, this);
        locationManager.getLastKnownLocation(gpsProvide);

    }

    public void onLocationChanged(Location location) 
    {       

        if (location != null) 
        {
            this.latitude = location.getLatitude();
            this.longitude = location.getLongitude();  
            System.out.println("Lat "+latitude+" Long "+longitude);
            this.gpsSupported = true;
        }
        else
        {           
             this.gpsSupported = false;
        }
    }

     public void getGPS()
     {
         Location location=null;
         try{
            location = locationManager.getLastKnownLocation(gpsProvide); 

            if (location != null) 
            {
                this.latitude = location.getLatitude();
                this.longitude = location.getLongitude();  
                System.out.println("Lat------------ "+latitude+" Long------------- "+longitude);
                this.gpsSupported = true;

                Data.lat=location.getLatitude();
                Data.lon=location.getLongitude();
            }
            else
            {               
                 this.gpsSupported = false;
            }
         }catch(Exception ex)
         {

         }

     }



    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
    }


    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
    }


    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }


    public double getLatitude()
    {
        return this.latitude;        
    }


    public double getLongitude()
    {
        return this.longitude;       
    }


    public boolean isGpsSupported()
    {
        return gpsSupported;        
    }
}
</code></pre>

<p>Thanks &amp; Regards</p>
