我想访问内部哈希图,所以我可以创建一个地理围栏,其中每个地理围栏都有一个自定义半径。
我已经在互联网上寻找了这个问题的答案,但是我似乎找不到任何看起来相似的代码,而其他有关如何访问嵌套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));
}
答案 0 :(得分:0)
link
返回以LatLng为键的映射项。因此,要访问它们,您需要entry.getValue()
和entry.getValue().getKey().latitude
。
答案 1 :(得分:0)
您缺少getKey()调用。您需要这个;
entry.getValue().getKey().latitude
答案 2 :(得分:0)
代替
entry.getValue().latitude, //error: cant access symbol Latitude
entry.getValue().longitude, //error: cant access symbol Longitude
使用以下语句:
entry.getValue().get("latitude");
entry.getValue().get("longitude");