android - Why doesn't onLocationChanged method get called in service? -
i getting current location in form of latitudes , longitudes. problem once coordinates doesn't updated when move location.i think onlocationchanged method not getting called. read here http://www.lengrand.fr/2013/10/onlocationchanged-is-never-called-on-android/ doesn't called itself. have gone through of tutorials , can't find solution.so how can call onlocationchanged method in service. please suggest me step step.
my codes follow:
public class gpstracker extends service implements locationlistener { public location getlocation() { try { locationmanager = (locationmanager) mcontext .getsystemservice(location_service); // getting gps status isgpsenabled = locationmanager .isproviderenabled(locationmanager.gps_provider); // getting network status isnetworkenabled = locationmanager .isproviderenabled(locationmanager.network_provider); if (!isgpsenabled && !isnetworkenabled) { // no network provider enabled } else { this.cangetlocation = true; if (isnetworkenabled) { locationmanager.requestlocationupdates( locationmanager.network_provider, min_time_bw_updates, min_distance_change_for_updates, this); log.d("network", "network"); if (locationmanager != null) { location = locationmanager .getlastknownlocation(locationmanager.network_provider); if (location != null) { latitude = location.getlatitude(); longitude = location.getlongitude(); } } } // if gps enabled 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); log.d("gps enabled", "gps enabled"); if (locationmanager != null) { location = locationmanager .getlastknownlocation(locationmanager.gps_provider); if (location != null) { latitude = location.getlatitude(); longitude = location.getlongitude(); } } } } } } catch (exception e) { e.printstacktrace(); } return location; } } @override public void onlocationchanged(location location) { getlocation(); }
- make sure requestlocationupdates(...) locationmanager (which in case seems do)
- if inside building , device doesn't gps fix onlocationchanged(...) not called, had same issue (when debugging in home) going outside saw function called once gps fix retrieved.
Comments
Post a Comment