Android Location info withought onLocationChanged -
i'm writing simple service listens location changes. in onstart method have following
lm = (locationmanager) getsystemservice(context.location_service); locationlistener = new mylocationlistener(); lm.requestlocationupdates(locationmanager.gps_provider, 0, 0, locationlistener); then how service reacts changes handled in onlocationchanged(location loc) method.
however want initial location when service starts. suppose there hasn't been changes in location info, i'd use location info @ least once when service starts, if location hasn't changed. how so?
use getlastknownlocation here.
following snippet you.
locationmanager lm = (locationmanager)act.getsystemservice(context.location_service); criteria crit = new criteria(); crit.setaccuracy(criteria.accuracy_fine); string provider = lm.getbestprovider(crit, true); location loc = lm.getlastknownlocation(provider);
Comments
Post a Comment