I’ve been pretty puzzled by this one. It seems as though my implementation of either Google Maps or pulling the users location is wonky. Right now I’m getting extremely scattered results across devices, and I’m not sure why, but the Lat/Long is Zeroing out on occasion.
Does anyone have any ideas?
Here is the method that I’m using to get my current location.
try {
locationListener = new MyLocationListener();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, locationListener);
loc = locationManager.getLastKnownLocation("gps");
if (loc == null) {
loc = locationManager.getLastKnownLocation("network");
}
if (loc != null && loc.getLongitude() != 0.0
&& loc.getLatitude() != 0.0) {
sLng = (loc.getLongitude());
sLat = (loc.getLatitude());
}
} catch (Exception e) {
e.printStackTrace();
}
You’re using the last cached location. This is only reliable when GPS has been used recently (after the phone booted)
You have to use location obtained from the
onLocationChanged()callback to get more up to date locations.