Stanley Tutu Dinala Stanley Tutu Dinala - 2 years ago 155
Android Question

How to allow user to create and save marker on Firebase Database

I would like to users to add and save markers on Firebase database.
i am unsure of how to do it, i currently have the user adding the marker and saving it but it does not appear on others users app.

public void onMapLongClick(final LatLng latLng) {
LayoutInflater li = LayoutInflater.from(context);
final View v = li.inflate(R.layout.alert_layout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context);

builder.setPositiveButton("Create", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
EditText title = (EditText)v.findViewById(;
EditText snittle = (EditText)v.findViewById(;

Marker marker0 = mMap.addMarker(new MarkerOptions()
hash.put(marker0, R.drawable.agriculture);


editor.putString("title"+(locationCount-1), title.getText().toString());


this is my method for saving the marker on the Firebase Database

private void drawMarker(final LatLng latLng){

myRef.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
Agriculture marker = userSnapshot.getValue(Agriculture.class);

mMap.addMarker(new MarkerOptions().position(latLng))

public void onCancelled(DatabaseError databaseError) {
// Failed to read value


Answer Source

You should save coordinates of your location (Lat Long) on Firebase. And then you can retrieve and show markers on Map. Firebase Realtime Database this will let you know how to save and retrieve data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download