Location returned is null when provider is gps?
<p>I am trying to retrieve the my current location coordinates in the following piece of code</p>

<pre><code>LocationManager locationManager= (LocationManager) getSystemService(context);
    Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
</code></pre>

<p>I get the location coordinates when the provider is "<em>network</em>".</p>

<p>When i change the settings in the location and security options to enable "<strong>Use GPS satellites</strong>" option the provider changes to "<em>gps</em>".
In this case the location returned is null.</p>

<p>What could be the cause of this and how can it be rectified?</p>

<p>Thanks</p>
