any one can help me if there is a way to get current latitude and longitude without using GPS since it consumes the power and without internet since i need to get location in places without internet service .
Get current location without using GPS and without internet in android
De openkb
Sommaire |
Questions
Answers
Yes...Without GPS and internet connection you can get current location through NETWORK_PROVIDER
Try this code.
LocationManager lm = null;
boolean network_enabled = false;
if(lm==null)
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
try{
network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}catch(Exception ex){}
if(!network_enabled){
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setMessage(context.getResources().getString("Custom message"));
dialog.setPositiveButton(context.getResources().getString(R.string.open_location_settings), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
// TODO Auto-generated method stub
Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );
context.startActivity(myIntent);
//get gps
}
});
dialog.setNegativeButton(context.getString(R.string.Cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
// TODO Auto-generated method stub
}
});
dialog.show();
}
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/26649843/get-current-location-without-using-gps-and-without-internet-in-android