android - requestLocationUpdates not working automatically -


i creating android mobile application. want find current location.if lastknownlocation return null value not calling listener interface automatically.for reference have added code below. please give solution. in advance.

    location loc = lm.getlastknownlocation(locationmanager.gps_provider);         log.e("location============", loc + "");          if (loc != null) {             lat = loc.getlatitude();             lon = loc.getlongitude();         } else {             lm.requestlocationupdates(locationmanager.gps_provider, 0, 0,                     new locationlistener() {                          public void onlocationchanged(location location) {                             mtxtmessage.settext("onlocation changed");                             log.e("location============", location + "");                             if (location != null) {                                 log.v("location changed", location.getlatitude() + " , " + location.getlongitude());                                 mtxtmessage.settext("lat=" + location.getlatitude() + " lon=" + location.getlongitude());                             }                         }                          public void onproviderdisabled(string provider) {                             mtxtmessage.settext("onprovider disabled");                         }                          public void onproviderenabled(string provider) {                             mtxtmessage.settext("onprovider enabled");                         }                          public void onstatuschanged(string provider, int status,                                                     bundle extras) {                             mtxtmessage.settext("onstatus changed");                         }                     });         } 


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -