Карты Google для Android - Маркерное цветовое кодирование работает только для последних результатов Firestore - PullRequest
0 голосов
/ 01 ноября 2018

Я занимаюсь разработкой приложения для Android, в котором для записи маркеров на карте Google используются записи Cloud Firestore.

Сегменты маркеров, как и ожидалось. Тем не менее, когда я пытаюсь раскрасить их, правильно отображаются только последние записи. Например, если у меня есть две записи, которые нужно закрасить «HUE_BLUE», только вторая будет закрашена правильно, а первая закрашена в параметре по умолчанию в моем цикле (HUE_RED).

Ниже приведен код, который я использовал для создания маркеров карты и цветового кодирования маркеров:

public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    firebase.collection("PointsOfInterest").addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
            for (DocumentSnapshot doc2:queryDocumentSnapshots) {
                poiAddress_id = doc2.getLong("address_id").intValue();
            }
        }
    });

    firebase.collection("Events").addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
            for(DocumentSnapshot doc3:queryDocumentSnapshots) {
                eventAddress_id = doc3.getLong("address_id").intValue();
            }
        }
    });

    firebase.collection("Address").addSnapshotListener(new EventListener<QuerySnapshot>() {
        LatLng marker;
        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
            for (DocumentSnapshot doc:queryDocumentSnapshots) {
                latitude = doc.getDouble("address_latitude");   //Obtains the latitude for a given address
                longitude = doc.getDouble("address_longitude"); //Obtains the longitude for a given address
                address_id = doc.getLong("address_id").intValue();
                addressName = doc.getString("address_name");
                addressSuburb = doc.getString("address_suburb");
                addressState = doc.getString("address_state");
                addressPostcode = doc.getLong("address_postcode").intValue();
                docID = doc.getId();   //Obtains the name of the specific data record - this is used to label the marker
                marker = new LatLng(latitude, longitude);    //Creates a map marker utilising the latitude and longitude values retrieved from the database

                if (address_id == poiAddress_id) {
                    markerColour = BitmapDescriptorFactory.HUE_BLUE;
                } else if (address_id == eventAddress_id) {
                    markerColour = BitmapDescriptorFactory.HUE_YELLOW;
                } else {
                    markerColour = BitmapDescriptorFactory.HUE_RED;
                }

                mMap.addMarker(new MarkerOptions().position(marker).title(docID).snippet(addressName + " " + addressSuburb + ", " + addressState + " " + addressPostcode)
                        .icon(BitmapDescriptorFactory.defaultMarker(markerColour)));


        }
            mMap.moveCamera(CameraUpdateFactory.newLatLng(marker));
            mMap.animateCamera(CameraUpdateFactory.zoomTo(10));
        }
    });

Будем весьма благодарны за любые предложения относительно того, почему это может происходить.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...