我正在做一个来自 coursera 的作业,我正在编写一张地图,该地图显示标记以指出发生地震的地点。因此,如果地震发生在 2000 年之后,我想将标记的颜色更改为黄色,如果在 2000 年之前,我想将标记的颜色更改为灰色2000.在我的代码中,我使用 PointFeature 作为 ArrayList 中的数据类型,它存储诸如年份到标记改变颜色的信息。我正在使用展开地图。
List<PointFeature> bigEqs = new ArrayList<PointFeature>();
Location valLoc = new Location(-38.14f,-73.03f);
Feature valEq = new PointFeature(valLoc);
bigEqs.add((PointFeature) valEq);
valEq.addProperty("title", "Valvidivia,Chile");
valEq.addProperty("magnitude","9.5");
valEq.addProperty("date", "May 22,1960");
valEq.addProperty("year", "1960");
Location valLoc1 = new Location(60.59f,-147.848f);
Feature alaskaEq = new PointFeature(valLoc1);
bigEqs.add((PointFeature) alaskaEq);
alaskaEq.addProperty("title", "Prince William Sound ,Southern Alaska");
alaskaEq.addProperty("magnitude","9.2");
alaskaEq.addProperty("date", "March 28,1964");
alaskaEq.addProperty("year", "1964");
Location valLoc2 = new Location(3.30f,95.98f);
Feature sumantraEq = new PointFeature(valLoc2);
bigEqs.add((PointFeature) sumantraEq);
sumantraEq.addProperty("title", "Sumatra-Andaman Islands ");
sumantraEq.addProperty("magnitude", " 9.1");
sumantraEq.addProperty("date", " December 26,2004");
sumantraEq.addProperty("year", " 2004");
Location valLoc3 = new Location(38.30f,142.37f);
Feature japanEq = new PointFeature(valLoc3);
bigEqs.add((PointFeature) japanEq);
japanEq.addProperty("title", "Tohuku(Eastern coast of Honshu) ,Japan");
japanEq.addProperty("magnitude", " 9.1");
japanEq.addProperty("date", "November 3 , 2011 ");
japanEq.addProperty("year", "2011 ");
Location valLoc4 = new Location(52.62f,159.78f);
Feature kamchatkaEq = new PointFeature(valLoc4);
bigEqs.add((PointFeature) kamchatkaEq);
kamchatkaEq.addProperty("title", "Kamchatka,Russia ");
kamchatkaEq.addProperty("magnitude", " 9.0");
kamchatkaEq.addProperty("date", "April 24,1952 ");
kamchatkaEq.addProperty("year", " 1952");
List<Marker> markers1 = new ArrayList<Marker>();
for(PointFeature eq:bigEqs) {
markers1.add(new SimplePointMarker(eq.getLocation(),eq.getProperties()));
} for(Marker mk:markers1) {
if( mk.getProperty("year")>2000) {
mk.setColor(color(255,255,0));
}else {
mk.setColor(color(128,128,128));
}
map.addMarker(mk);
}
但它显示错误:它不能在这里将 obj 转换为 int,if( mk.getProperty("year")>2000)