Reputation: 3971
The question is self explainatory. On debugging I see the location as null. Please suggest what further to triage.
locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
....
// 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);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
On debugging I see that gpsEnabled is alwaysreturned false. GPS is turned on on the emulator
Upvotes: 0
Views: 751
Reputation: 93708
Based on the code, I'm assuming you're using GPSTracker or some derivation of it (which you shouldn't that code is broken). If so, the gpsEnabled value just tells you whether its possible to use GPS, not whether its actually on and capable of giving you a value right now.
Upvotes: 1
Reputation: 7214
You're using an emulator. It hasn't yet requested a location so you'll need to call requestLocationUpdates()
or requestSingleUpdate()
so that it stores a location for the device.
Another way to do this is to try clicking the menu on the right side of the emulator that looks like three dots and go to the Location section. If you put in a latitude and longitude in there and click "Send", does that work?
Upvotes: 0