android - My Latitude and Longitude are not changing values when I move locations -


i trying show latitude , longitude move around, stays @ 1 value , not change. can tell me wrong code? have updated manifest file i'm not sure why it's not working properly. make calls in writetofile method in main activity.

package com.explorer.extractor;  import android.app.service; import android.content.context; import android.content.intent; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.os.bundle; import android.os.ibinder; import android.util.log;  public class gpstracker extends service implements locationlistener {     private final context mcontext;      //flag gps status     boolean isgpsenabled = false;      //flag network status     boolean isnetworkenabled = false;      boolean cangetlocation = false;      location location; //location     double latitude; //latitude     double longitude; //longitude      //the minimum distance change updates in meters     private static final long min_distance_change_for_updates = 0; //10 meters      //the minimum time between updates in milliseconds     private static final long min_time_bw_updates = 1000 * 60 * 0; //0 minute      //declare location manager     protected locationmanager locationmanager;      public gpstracker(context context) {         this.mcontext = context;         getlocation();     }      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;                 //first location network provider                 if (isnetworkenabled) {                     locationmanager.requestlocationupdates(locationmanager.network_provider, min_time_bw_updates, min_distance_change_for_updates, this);                     log.i("network", "network");                     if (locationmanager != null) {                         location = locationmanager.getlastknownlocation(locationmanager.network_provider);                         log.i("network", "number 1");                         if (location != null) {                             log.i("network", "is not null");                             latitude = location.getlatitude();                             longitude = location.getlongitude();                             log.i("network", "the latitude " + latitude);                         }                     }                 }                 //if gps enabled lat/long usig gps services                 else if (isgpsenabled) {                     if (location == null) {                         locationmanager.requestlocationupdates(locationmanager.gps_provider, min_time_bw_updates, min_distance_change_for_updates, this);                         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) {     }      @override     public void onproviderdisabled(string provider) {     }      @override     public void onproviderenabled(string provider) {     }      @override     public void onstatuschanged(string provider, int status, bundle extras) {     }      public ibinder onbind(intent arg0) {         return null;     }      //function latitude     public double getlatitude() {         if (location != null) {             latitude = location.getlatitude();         }         return latitude;     }      //function longitude     public double getlongitude() {         if (location != null) {             longitude = location.getlongitude();             log.i("long", "the long " + longitude);         }         log.i("long", "the long isnt working");         return longitude;     }      /**      * function check if best network provider      *      * @return boolean      */     public boolean cangetlocation() {         return this.cangetlocation;     }      /**      * stop using gps listener      * calling function stops using gps in app      */     public void stopusinggps() {         if (locationmanager != null) {             locationmanager.removeupdates(gpstracker.this);         }     } } 

you should using onlocationchanged() update lat longs. empty, i'm not sure how updating ui


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -