i using gps services derive latitude & longitude in app. able latitude , longitude when signal avialable. once fix, if have go place gps not able location fix, still shows last location. want current location , not otherwise. have tried using onlocationchanged() , ongpsstatuschanged() both gps status isnt giving me result.
@override public void ongpsstatuschanged(int arg0) { // todo auto-generated method stub if (event == gpsstatus.gps_event_started) { log.d("zmenagps" , "gps event started "); gpsstatus gs = mlocmanager.getgpsstatus(null); toast.maketext(getapplicationcontext(),string.valueof(gs),toast.length_long).show(); } else if (event == gpsstatus.gps_event_stopped) { log.d("zmenagps" , "gps event stopped "); gpsstatus gs = mlocmanager.getgpsstatus(null); log.d("zmenagpsgps status" , string.valueof(gs)); toast.maketext(getapplicationcontext(),string.valueof(gs),toast.length_long).show(); } else if (event == gpsstatus.gps_event_first_fix) { log.d("zmenagps" , "gps fixace "); toast.maketext(getapplicationcontext(),"first fix",toast.length_long).show(); } else if (event == gpsstatus.gps_event_satellite_status) { log.d("zmenagps" , "gps evet neco "); } }
use network_provider instead updated location time. this..
public location getlocation() { try { locationmanager = (locationmanager) mcontext .getsystemservice(context.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, 0, 0, locationlistenernetwork); // 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, 0, 0, locationlistenergps); // 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(); } } } } } // if (!isgpsenabled) { // showsettingsalert(); // } } catch (exception e){ e.printstacktrace(); } return location; }
hope helps
Comments
Post a Comment