android - GpsStatus.GPS_EVENT_FIRST_FIX often takes a long time to be called -


i have android device mounted inside car. need receive gps location updates every second. problem necessary data (number of satellites , coordinates , time etc .. )

but reason "gpsstatus.gps_event_first_fix" not called or if called takes long time (like 30 minutes .. )

why ? here code :

    public class extprotocolservice extends service implements gpsstatus.listener {          private gpsstatus gpsstatus;         private gpsdata gpsdata;         private locationmanager locationmanager;         private locationlistener locationlistener;  @override public void oncreate() {               locationmanager = (locationmanager)                    getsystemservice(this.location_service);             criteria criteria = new criteria();             criteria.setaccuracy(criteria.accuracy_fine);             string provider = locationmanager.getbestprovider(criteria, true);             if(provider.equals("gps"))             {                 locationlistener = new locationlistener() {                      @override                     public void onstatuschanged(string provider, int status,                             bundle extras) {                         // todo auto-generated method stub                      }                      @override                     public void onproviderenabled(string provider) {                         // todo auto-generated method stub                         // not used                      }                      @override                     // not used                     public void onproviderdisabled(string provider) {                         // todo auto-generated method stub                      }                      // update location parameters when location changed                     @override                     public void onlocationchanged(location location) {                         gpsdata.setlatitude(location.getlatitude());                         l.m("latlong", "latitude " + location.getlatitude());                         gpsdata.setlongitude(location.getlongitude());                         l.m("latlong", "longitude " + location.getlongitude());                         gpsdata.setspeed(location.getspeed());                         gpsdata.setheading(location.getbearing());                         gpsdata.setaltitude(location.getaltitude());                         gpsdata.sethdop(location.getaccuracy());                      }                 };                 locationmanager.requestlocationupdates(locationmanager.gps_provider,                         1000, 0, locationlistener); // update location every 1000 ms                 locationmanager.addgpsstatuslistener(this);               }     }          @override         public void ongpsstatuschanged(int event) {             switch (event) {             case gpsstatus.gps_event_first_fix:                 gpsdata.setlocked(true); // gps locked                 break;             case gpsstatus.gps_event_stopped:                 gpsdata.setlocked(false); // gps unreachable                 break;             }              gpsstatus = locationmanager.getgpsstatus(null);              // calc number of satelites fixed             iterable<gpssatellite> sats = gpsstatus.getsatellites();             int satellites = 0;             int satellitesinfix = 0;             int timetofix = gpsstatus.gettimetofirstfix();             (gpssatellite sat : sats) {                 if (sat.usedinfix()) {                     satellitesinfix++;                 }                 satellites++;             }              gpsdata.setnumsatellites(satellitesinfix);             l.m("gps", gpsdata.tostring());          }       } 

edit : can not use google location api's ..


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -