I have a method which registers a listener and requests location updates. I would like to the location coordinates in the current method itself, not in the onLocationChanged method.
My code is:-
myclass {
onCreate {
location_Manager = (LocationManager) getSystemService (Context.LOCATION_SERVICE);
locLstnr = new myLocationlistener();
locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, Loc_listener.MINIMUM_TIME_BETWEEN_UPDATES, Loc_listener.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, locLstnr);
}
class myLocationListener () {
onLocationChanged() { ... }
onProviderDisabled() { ... }
onProviderEnabled() { ... }
}
}
I know i can get getLastKnownLocation() , but incase it is not available, isn't it possible to get the location at all? This and this are a similar questions, but doesn't help me. I don't have problems with using onLocationChanged method, but i need to have the location in the onCreate method. Is that possible? One way might be to store the location onto a variable in the myLocationListener and access it, but is there an alternative or a better solution?