1

I want to get last location (With any way) without enabling location services on device , is this possible?
How should i do this?

Ali Hasanzade
  • 151
  • 15
  • try this,http://stackoverflow.com/questions/25483352/how-to-get-last-known-location-for-location-manager-in-android – Jignesh Jain Mar 25 '15 at 08:21

3 Answers3

0

there are three ways to find your location,refer this

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();

int cellid= cellLocation.getCid(); int celllac = cellLocation.getLac();

rKrishna
  • 1,399
  • 12
  • 22
0

If you want to get location without GPS then you should use NETWORK_PROVIDER to get location :

I have taken this module from AndroidHive website You can refer more there.

Your query will be solved with this method getLocation()

public Location getLocation() {
    try {
        locationManager = (LocationManager) mContext
                .getSystemService(LOCATION_SERVICE);

        // getting GPS status
        isGPSEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);

        // getting network status
        isNetworkEnabled = locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {
            // no network provider is enabled
        } else {
            this.canGetLocation = true;
            // First get location from Network Provider
            if (isNetworkEnabled) {
                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("Network", "Network");
                if (locationManager != null) {
                    location = locationManager
                            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    if (location != null) {
                        latitude = location.getLatitude();
                        longitude = location.getLongitude();
                    }
                }
            }
            // if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled) {
                if (location == null) {
                    locationManager.requestLocationUpdates(
                            LocationManager.GPS_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.d("GPS Enabled", "GPS Enabled");
                    if (locationManager != null) {
                        location = locationManager
                                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return location;
}
Kushal
  • 8,100
  • 9
  • 63
  • 82
-1

You can use NETWORK_PROVIDER as service parameter in the method getLastKnownLocation.

Arun PS
  • 4,610
  • 6
  • 41
  • 56