android - locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER) returns null -


i've location app send location of phone database. when try location network (no 3g on) works! when turn 3g on doesn't work because code: locationmanager.getlastknownlocation(locationmanager.gps_provider);

always return null. here full locationhandler..

code of locationhandler class.

package info.androidhive.loginandregistration.location;  import android.content.context; import android.content.intent; import android.location.address; import android.location.geocoder; import android.location.location; import android.location.locationmanager; import android.util.log;  import java.io.ioexception; import java.util.list; import java.util.locale;  public class locationhandler {      context mcontext = null;     context ctx;     double lat;     double long;     location localization;     locationmanager locationmanager;     boolean gpsactivate = false;     boolean gprsactivate = false;     boolean getubicationbool;      private double mlastlatitudelocation = 0;     private double mlastlongitudelocation = 0;     intent intent;      // flag gps status     public boolean isgpsenabled = false;      // flag network status     boolean isnetworkenabled = false;      // flag gps status     boolean cangetlocation = false;      location location; // location     double latitude; // latitude     double longitude; // longitude      public locationhandler(context context) {          mcontext = context;     }      private void configurationmanager() {         locationmanager = (locationmanager) mcontext.getsystemservice(context.location_service);         // getting gps status         isgpsenabled = locationmanager.isproviderenabled(locationmanager.gps_provider);         log.v("isgpsenabled", "=" + isgpsenabled);         // getting network status         isnetworkenabled = locationmanager.isproviderenabled(locationmanager.network_provider);          log.v("isnetworkenabled", "=" + isnetworkenabled);     }      public location getlocation() {         try {              configurationmanager();              if (isgpsenabled == false && isnetworkenabled == false) {                 // no network provider enabled                 return null;             } else {                 this.cangetlocation = true;                 if (isnetworkenabled) {                     location = null;                     log.d("network", "network - location ");                     if (locationmanager != null) {                         location = locationmanager.getlastknownlocation(locationmanager.network_provider);                         if (location != null) {                             latitude = location.getlatitude();                             longitude = location.getlongitude();                         }                     }                 }                 if (isgpsenabled) {                     location = null;                     if (location == null) {                         log.d("gps enabled", "gps enabled - location");                         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;     } } 

1-you have make sure have permission in manifest file added:

access_fine_location 

2- gps provider according sdk is: "this provider determines location using satellites. depending on conditions, provider may take while return location fix." means have turn on gps not 3g


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -