Finding the users location
android
Solution
Try this,
protected LocationManager locationManager;
Context context;
public String gps_loc;
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 10, new MyLocationListener());
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
gps_loc = String.format("%1$s" +"-"+"%2$s",location.getLongitude(), location.getLatitude());
Toast.makeText(Clockin.this, gps_loc, Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String s, int i, Bundle b) {
Toast.makeText(class.this, "Provider status changed", Toast.LENGTH_SHORT).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(class.this,"Provider disabled by the user. GPS turned off",Toast.LENGTH_SHORT).show();
final AlertDialog alertDialog = new AlertDialog.Builder(class.this).create();
alertDialog.setTitle("Activate GPS...");
alertDialog.setButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
}
});
alertDialog.show();
}
public void onProviderEnabled(String s) {
Toast.makeText(class.this,"Provider enabled by the user. GPS turned on", Toast.LENGTH_SHORT).show();
}
}
Problem
I am developing an android application. I need to find the location of the user as soon as he/she logs in to the application. I do not want maps to be displayed, the location should be identified without the user's knowledge. Is it possible to do this using the Google maps API? or is there any other way to do this? Thanks