Reputation: 103
Can we get device's current latitude and longitude with out using internet? I am using following codes.. I am triggering the location listener after the button click.
locationListener = new MyLocationListener();
location.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 20, locationListener);
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
longitude = String.valueOf(loc.getLongitude());
latitude = String.valueOf(loc.getLatitude());
...
}
}
It fetches longitude and latitude values fine when its connected to internet but returns null when not connected to internet.
What could be the problem? Does LocationManager.NETWORK_PROVIDER, 5000, 20, locationListener need internet to get lat and long?
If internet is required then what's the difference between network provider NETWORK_PROVIDER and GPS_PROVIDER ?
Upvotes: 0
Views: 2775
Reputation: 33792
The network provider translates Cell ID/WiFi readings information to a lat/long address and it needs a data connection to do so. (It accesses Google's servers which has a database of such information)
Use the GPS Provider. It does not need internet.
Upvotes: 1