Ibrahim Baz Ibrahim Baz - 8 days ago 9
Android Question

Set up Marker in Map onKeyEnterd()

Why I Can't See Marker on the Map? I wanted To get Latitude and Longitude from Firebase Database.

I missing something or what ?

My

@override
Method
onKeyEnterd()


@Override
public void onKeyEntered(String key, GeoLocation location) {
// Add a new marker to the map

user_id = firebaseAuth.getCurrentUser().getUid();

DatabaseReference geoLocation = databaseReference.child(user_id).child("longitude");
DatabaseReference geoLocation1 = databaseReference.child(user_id).child("latitude");

String Lng = String.valueOf(geoLocation);
double LangDouble = Double.parseDouble(Lng);
String Lat = String.valueOf(geoLocation1);
double LatDouble= Double.parseDouble(Lat);

runnersNearby.add(key);
Marker marker = this.map.addMarker(new MarkerOptions().position(new LatLng(LangDouble,LatDouble) )
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.title("I Serve"));
this.markers.put(key, marker);
}

Answer

I find the solution with, and here is there right code:

i will add the mark to my onMapReady() Method

and this method below will added to my method

private void createMarker() {
    Firebase ref = new Firebase("https://ifirebase-.firebaseio.com/path/");
    //Query queryRef = ref.orderByChild("latitude");
    ref.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
                markerLocation marker = userSnapshot.getValue(markerLocation.class);
                Double lat = Double.parseDouble(String.valueOf(marker.getLatitude()));
                Double log = Double.parseDouble(String.valueOf(marker.getLongitude()));
                LatLng latLng = new LatLng(lat, log);
                map.addMarker(new MarkerOptions().position(latLng));
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}