I want to access the Inner Hashmap so I can great a geofence, where each geofence has a custom radius.
I have looked all over the internet for a answer to this problem, but I dont seem to find any bit of code that looks similar and the other posted about how to access a nested Hashmap dont help my problem.
Please any help or advice will be appreciated.
I have tried everything from what I have read up on related posts but nothing seems to work.
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());
}
}
// this is where the Hashmap stores the Values
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));
}
entry.getValue()
returns a map entry of which LatLng is the key. So to access them you need entry.getValue().getKey().latitude
and entry.getValue().getKey().longitude
.