Issue in getting the location in android device -


i stuck in problem lat , long in android device. have @ code follows:-

public newlocationactivity(final context mcontext) {                  locationmanager = (locationmanager) mcontext                 .getsystemservice(context.location_service);                  locationlistener = new locationlistener() {              public void onlocationchanged(location location) {              updatelocation(location);                    msharedpreferences=mcontext.getsharedpreferences(homesafepref.homesafelocationpref,context.mode_private);                 sharedpreferences.editor prefeditor=msharedpreferences.edit();                  string latitude=string.valueof(currentlatitude);                 string longitude=string.valueof(currentlongitude);                 string heading=string.valueof(currentheading);                 string horizaccuracy=string.valueof(currenthorizaccuracy);                  prefeditor.putstring("latitude", latitude);                 prefeditor.putstring("longitude", longitude);                 prefeditor.putstring("heading", heading);                 prefeditor.putstring("horizaccuracy", horizaccuracy);                 prefeditor.commit();                  }              public void onstatuschanged(string provider, int status,                     bundle extras) {             }              public void onproviderenabled(string provider) {              }              public void onproviderdisabled(string provider) {              }          };          locationmanager.requestlocationupdates(                 locationmanager.network_provider, 0, 0, locationlistener);     }     void  updatelocation(location location) {      currentlocation = location;      this. currentlatitude = currentlocation.getlatitude();      this. currentlongitude = currentlocation.getlongitude();       geofield=new geomagneticfield(             double.valueof(location.getlatitude()).floatvalue(),             double.valueof(location.getlongitude()).floatvalue(),             double.valueof(location.getaltitude()).floatvalue(),             system.currenttimemillis()          );      this.currentheading=geofield.getinclination();     this.currenthorizaccuracy=currentlocation.getaccuracy();     this.speed=(int) currentlocation.getspeed();  } 

when creating object of class newlocationactivity constructor works .but problem updatelocation method not runs.why dont know...but times in other devices runs , lat , long easily.please let me know why getting lat , long 0,0.thanks in advance..

use code :it gets lat ,long ur internet.u can use gps getting lat ,long .it accurate wont work inside building or may in devices because of receiving capacity.the best way use both , write condition if gps lat,long null go wifi

public class newlocationactivity extends activity implements locationlistener {       private locationmanager locationmanager;      /**      * called when activity first created.      */     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.digitalsignature);             getlocation();      }       public string[] getlocation()     {          string[] locationarray=new string[2];           locationmanager = (locationmanager) digitalsignatureactivity.this.getsystemservice(location_service);         // getting network status         boolean  isnetworkenabled = locationmanager.isproviderenabled(locationmanager.network_provider);          // minimum distance change updates in meters         final long min_distance_change_for_updates = 10; // 10 meters          // minimum time between updates in milliseconds         final long min_time_bw_updates = 1000 * 60 * 1; // 1 minute          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 location = locationmanager                         .getlastknownlocation(locationmanager.network_provider);                 if (location != null) {                     locationarray[0] = string.valueof(location.getlatitude());                     locationarray[1] = string.valueof(location.getlongitude());                  }             }         }         return locationarray;      }       /**      * stop using location listener      * calling function stop using location updates in app      * */     public void stopusinglocationupdates(){         if(locationmanager != null){             locationmanager.removeupdates(digitalsignatureactivity.this);         }           }      @override     public void onlocationchanged(location arg0) {     // todo auto-generated method stub       }       @override      public void onproviderdisabled(string arg0) {     // todo auto-generated method stub      }       @override       public void onproviderenabled(string arg0) {     // todo auto-generated method stub      }       @override      public void onstatuschanged(string arg0, int arg1, bundle arg2) {     // todo auto-generated method stub       }    } 

also in manifest declare this

  <uses-permission android:name="android.permission.internet" />   <uses-permission android:name="android.permission.access_coarse_location"/> 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -