Check this little example, it should solve your problem. Please check onConnected() method, there is the logic you need, I also let you all the code that make it work all together if you need:
package current_location_to_firebase.mytrendin.com.currentlocation;
import android.location.Location;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.firebase.FirebaseApp;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity implements
ConnectionCallbacks, OnConnectionFailedListener {
private static final String TAG = "CurrentLocationApp";
private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;
private TextView mLatitudeText;
private TextView mLongitudeText;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mLocationDatabaseReference;
Button saveLocationToFirebase;
String value_lat = null;
String value_lng=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseApp.initializeApp(this);
mFirebaseDatabase = FirebaseDatabase.getInstance();
mLocationDatabaseReference= mFirebaseDatabase.getReference().child("my current location");
mLatitudeText = (TextView) findViewById((R.id.latitude_text));
mLongitudeText = (TextView) findViewById((R.id.longitude_text));
saveLocationToFirebase=(Button)findViewById(R.id.save_location);
buildGoogleApiClient();
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onConnected(Bundle connectionHint) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
value_lat= String.valueOf(mLastLocation.getLatitude());
value_lng =String.valueOf(mLastLocation.getLongitude());
mLatitudeText.setText(value_lat);
mLongitudeText.setText(value_lng);
saveLocationToFirebase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mLocationDatabaseReference.push().setValue("Latitude : "+value_lat +" & Longitude : "+value_lng);
Toast.makeText(MainActivity.this ,"Location saved to the Firebasedatabase",Toast.LENGTH_LONG).show();
}
});
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode());
}
@Override
public void onConnectionSuspended(int cause) {
Log.i(TAG, "Connection suspended");
mGoogleApiClient.connect();
}
}
Remember in your database rules to set it to true if they are turned false for just auth users to post into it

saveLocationToFirebase is a button that should be initialized in your XML, so when we click it you update the values to the database, if you want them to do it by itself attach a listener to the latitude and longitude, so, when they change it will prompt the upload to the database.