3

I am creating an app related to location, so i need to get current latitude and longitude without having Internet Connection.

Please help me out. I am novice with Location Manager. Suggestion appreciated. Thanks Regards.

  • 2
    Using gps you can get current location without internet. http://stackoverflow.com/questions/22741632/get-current-location-using-gps-in-android –  Dec 29 '14 at 13:48
  • @officebrain This code works fine with Internet. I need to get Latitude and Longitude without Internet connection. – Shoeb Ahmed Siddique Dec 29 '14 at 13:51
  • 1
    You can stop internet and go to out door area and get current location. –  Dec 29 '14 at 14:00

1 Answers1

1

There are Two ways to get the Location

1)Network provider

2)GPS Provider

for getting location through GPS Provider(without Internet) Use LocationManager.GPS_PROVIDER as mentioned in the below Code

locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(
                                    LocationManager.GPS_PROVIDER,
                                    MIN_TIME_BW_UPDATES,
                                    MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

if (locationManager != null) {

            location =locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                            if (location != null) {
                                latitude = location.getLatitude();
                                longitude = location.getLongitude();

                            }
                        }

and to know about the GPS status, whether enabled or not

boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

and for Removing Updated

if(locationManager != null){locationManager.removeUpdates(this);
Jamil
  • 5,457
  • 4
  • 26
  • 29