简体   繁体   English

带有循环的Google Maps API

[英]Google Maps API with loop

I am using a loop to add markers to a Google Map. 我正在使用循环将标记添加到Google Map。 The loop did work before I implemented the if-statements. 在执行if语句之前,该循环确实起作用。 Why wont it work now? 为什么现在不起作用? I just dont understand why it wont work, it seems logical? 我只是不明白为什么它不起作用,似乎合乎逻辑?

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)));
    }
}

You cant compare String with == sysmbol 您不能将String与== sysmbol进行比较

you need to use Icon.equels("second string") 您需要使用Icon.equels("second string")

== symbol compares Object ref. ==符号比较对象参考。 not actual data 不是实际数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM