0
我正在使用循環向Google地圖添加標記。在我執行if語句之前,循環確實有效。爲什麼現在不工作?我只是不明白爲什麼它不會工作,這似乎是合乎邏輯的?帶環路的Google Maps API
for(int i=1;i<statoilnumber;i++) {
String XCord = sharedPreferences.getString("XCord"+i,"0");
String YCord = sharedPreferences.getString("YCord"+i, "0");
int Title = sharedPreferences.getInt("Title" + i, 0);
String Info = sharedPreferences.getString("Info" + i, "0");
String Icon = sharedPreferences.getString("Icon" + i, "4");
String realTitle = Integer.toString(Title);
// Drawing marker on the map
if(Icon=="4") {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(YCord), Double.parseDouble(XCord)))
.title(realTitle + ". Statoil")
.snippet(Info)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.statoil_correct)));
}
if(Icon=="1") {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(YCord), Double.parseDouble(XCord)))
.title(realTitle + ". Statoil")
.snippet(Info)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.approved_scale)));
}
if(Icon=="2") {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(YCord), Double.parseDouble(XCord)))
.title(realTitle + ". Statoil")
.snippet(Info)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.clock_scale)));
}
if(Icon=="3") {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(YCord), Double.parseDouble(XCord)))
.title(realTitle + ". Statoil")
.snippet(Info)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.death_scale)));
}
}
定義不起作用......它是否會拋出異常?它多次繪製東西?它是否總是繪製「Icon == 4」選項?你真的應該做一個開關或一個if/else(無論哪種情況,如果Icon與你的任何值都不匹配,包括一個默認選項) – Foon
Icon是一個String,使用'(Icon.equals(「4」 ))'等等...... –
http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java –