0

In Android if LocationServices is disabled, is there any way that I can get the current location through wifi/network. I know there is one way of showing the user a popup to change his LocationSettings , but I don't want to show the popup.

So is there any way of getting the current location even if LocationServices is disabled ?

Sasank Sunkavalli
  • 3,864
  • 5
  • 31
  • 55
  • yes it is possible.check below url for reference.http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ – malli Mar 15 '16 at 09:02
  • If the user has disabled all the location tracking options in the Settings, then you cannot discover his/her location by any Google APIs. You can get last known location, as explained here - http://developer.android.com/training/location/retrieve-current.html . But bear in mind that location can be outdated, to a lesser or greater extent. – nstosic Mar 15 '16 at 09:05

2 Answers2

0

use LocationManager.NETWORK_PROVIDER instead of LocationManager.GPS_PROVIDER

The entire code and how to use is given here : http://developer.android.com/guide/topics/location/strategies.html

// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider.
      makeUseOfNewLocation(location);
    }

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

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
A Biswas
  • 421
  • 6
  • 12
  • This code doesn't work if the LocationServices is disabled , onLocationChanged callback is not getting called . But if the LocationServices is enabled , it is getting called. – Sasank Sunkavalli Mar 15 '16 at 09:39
0

Yes of course, you can use:

// let Android select the right location provider for you
String myProvider = locationManager.getBestProvider(myCriteria, true); 

check this for more details good-way-of-getting-the-users-location-in-android and this Location Strategies

Community
  • 1
  • 1
Marzouk
  • 2,650
  • 3
  • 25
  • 56