android - toast is displayed before getting GPS location -


when press button start getting location , toast message comes , shows lat:0 lon:0 (the initialized values).

after few seconds must press again button location , shows location.

what can that?

(as understand , if use delay doesn't solve problem.i want toast message wait until location)

 if(gps.cangetlocation()){   latitude = gps.getlatitude();  longitude = gps.getlongitude();      toast.maketext(getapplicationcontext(), "your location  \nlat: " + latitude + "\nlong: " + longitude, toast.length_long).show();                     ... 

i used sth like:

 private void showtoast() {                new thread() {                    public void run() {                     try {                           while (message) {                            runonuithread(new runnable() {                                 @override                                 public void run() {                             if(gps.cangetlocation()){                                  latitude = gps.getlatitude();                     longitude = gps.getlongitude();          toast.maketext(getapplicationcontext(), "your location \nlat: " + latitude + "\nlong: " + longitude, toast.length_long).show();                                  message=false;                                   }else{                                      gps.showsettingsalert();                                 }                            });                            thread.sleep(1000);                        }                     }   catch (interruptedexception e) {                         e.printstacktrace();                    }                    }                }.start();                }         

but doesn't seem work.also ,is there way show message until location found?

as codemagic said, use diffrent thead keep checking. gps needs time fix.

maybe can service manages gps fix while app running.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -