Как получить доступ к вложенной Hashmap - PullRequest
0 голосов
/ 10 мая 2019

Я хочу получить доступ к Inner Hashmap, чтобы создать большую геозону, где каждая геозона имеет свой радиус.

Я искал во всем Интернете ответ на эту проблему, но мне кажется, что я не нахожу какой-либо фрагмент кода, который выглядит аналогично, а другие сообщения о том, как получить доступ к вложенному Hashmap, не помогают моей проблеме.

Пожалуйста, любая помощь или совет будут оценены.

Я перепробовал все из того, что прочитал в соответствующих постах, но, похоже, ничего не работает.


private void setmGeofenceList(HashMap<String, Map.Entry<LatLng,Integer>> mhashMap)
    {
        for (Map.Entry<String, Map.Entry<LatLng,Integer>> entry : mhashMap.entrySet()) {

            mGeofenceList.add(new Geofence.Builder()
                    .setLoiteringDelay(1000)
                    .setNotificationResponsiveness(1000)
                    // Set the request ID of the geofence. This is a string to identify this
                    // geofence.
                    .setRequestId(entry.getKey())
                    // Set the circular region of this geofence.
                    .setCircularRegion(

                            //THIS is the problem, this wont access the LatLng Value that is inside the inner hashmap
                            entry.getValue().latitude, //error: cant access sysmbol Latitude

                            entry.getValue().longitude, //error: cant access sysmbol Longitude


                    )
                    // Set the expiration duration of the geofence. This geofence gets automatically
                    // removed after this period of time.
                    .setExpirationDuration(Geofence.NEVER_EXPIRE)

                    // Set the transition types of interest. Alerts are only generated for these
                    // transition. We track entry and exit transitions in this sample.
                    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
                            Geofence.GEOFENCE_TRANSITION_EXIT)

                    // Create the geofence.
                    .build());

        }
    }

// здесь Hashmap хранит значения

    static final HashMap<String, Map.Entry<LatLng,Integer>>RED_LINE_GEOFENCES = new HashMap<>();
    static {
        RED_LINE_GEOFENCES.put("PlatformA", new AbstractMap.SimpleEntry<>(new LatLng(-33.905679, 19.112890), 300));
        RED_LINE_GEOFENCES.put("Ticket Office", new AbstractMap.SimpleEntry<>(new LatLng(-33.911024, 19.119688), 300));
        RED_LINE_GEOFENCES.put("Maison", new AbstractMap.SimpleEntry<>(new LatLng(-33.886851, 19.076072), 300));
        RED_LINE_GEOFENCES.put("Mont Rochelle", new AbstractMap.SimpleEntry<>(new LatLng(-33.914458, 19.106716), 300));
        RED_LINE_GEOFENCES.put("Holden Manz", new AbstractMap.SimpleEntry<>(new LatLng(-33.934360, 19.113939), 300));
        RED_LINE_GEOFENCES.put("Charmonix", new AbstractMap.SimpleEntry<>(new LatLng(-33.899535, 19.127489), 300));
        RED_LINE_GEOFENCES.put("DieuDonne", new AbstractMap.SimpleEntry<>(new LatLng(-33.891131, 19.133831), 300));
        RED_LINE_GEOFENCES.put("Grande Provance", new AbstractMap.SimpleEntry<>(new LatLng(-33.899443, 19.103134), 300));
        RED_LINE_GEOFENCES.put("Rickety Bridge", new AbstractMap.SimpleEntry<>(new LatLng(-33.894788, 19.097545), 300));
    }

Ответы [ 3 ]

0 голосов
/ 10 мая 2019

Вам не хватает вызова getKey ().Вам это нужно;

 entry.getValue().getKey().latitude
0 голосов
/ 10 мая 2019

вместо

entry.getValue().latitude, //error: cant access symbol Latitude
entry.getValue().longitude, //error: cant access symbol Longitude

используйте эти утверждения:

entry.getValue().get("latitude");
entry.getValue().get("longitude");
0 голосов
/ 10 мая 2019

entry.getValue() возвращает запись карты, ключом которой является LatLng.Таким образом, чтобы получить к ним доступ вам нужно entry.getValue().getKey().latitude и entry.getValue().getKey().longitude.

...