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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -