Ibrahim Baz Ibrahim Baz - 3 months ago 47
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 ?



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);

Marker marker = this.map.addMarker(new MarkerOptions().position(new LatLng(LangDouble,LatDouble) )
.title("I Serve"));
this.markers.put(key, marker);


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() {
        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));

        public void onCancelled(FirebaseError firebaseError) {