[英]How to access nested Hashmap
我想訪問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));
}
entry.getValue()
返回LatLng為鍵的映射條目。 因此,要訪問它們,您需要entry.getValue().getKey().latitude
和entry.getValue().getKey().longitude
。
你缺少getKey()調用。 你需要這個;
entry.getValue().getKey().latitude
代替
entry.getValue().latitude, //error: cant access symbol Latitude
entry.getValue().longitude, //error: cant access symbol Longitude
使用這些陳述:
entry.getValue().get("latitude");
entry.getValue().get("longitude");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.