I have done this code where I ask for updates on location.I want to know if i implemented it correctly. Once page is opened, i request for updates ( preference to network over gps)...and i display the location in function onlocationchanged. I want to ask is it possible inside onlocationchanged i get location null similar when i do getlastknownlocation? i stopped using ghetlastknownlocation as it returns nulll at times and wrong values.
boolean isGPSEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = lm .isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { ProgressBar progress = (ProgressBar)findViewById(R.id.progress); progress.setVisibility(View.INVISIBLE); Utilities.showAlertDialog2(RegionalStoresMeActivity.this, "", ""+getResources().getString(R.string.nothing_enabled), false); } else if(isNetworkEnabled){ // lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0, this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0, this); } else if(isGPSEnabled ) { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,1,0, this); }