安卓工作室谷歌地图更改标记颜色



我想根据数据库中的颜色更改地图上的标记颜色。没有错误,所以 Idk 我的代码出了什么问题。我认为这是 for 循环,但 Idk 这里的正确逻辑是什么。

private void AllSpeciesLocation() {
    ArrayList<HashMap<String, String>> location = null;
    String url = "http://192.168.1.4/android_login_api/getLatLong.php";
    try {
        JSONArray data = new JSONArray(getHttpGet(url));
        location = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> map;
        for(int i = 0; i < data.length(); i++){
            JSONObject c = data.getJSONObject(i);
            search_species = c.getString("speciesid");
            map = new HashMap<String, String>();
            map.put("locationid", c.getString("locationid"));
            map.put("brgy", c.getString("brgy"));
            map.put("town", c.getString("town"));
            map.put("latitude", c.getString("latitude"));
            map.put("longitude", c.getString("longitude"));
            map.put("speciesid", c.getString("speciesid"));
            String url2 = "http://192.168.1.4/android_login_api/search_species_color.php?species_name=" + search_species;
            try {
                JSONArray data2 = new JSONArray(getHttpGet(url2));
                for(i = 0; i < data2.length(); i++){
                    JSONObject c2 = data.getJSONObject(i);
                    map.put("color", c2.getString("flowercolor"));
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
            location.add(map);
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

我的标记没有问题。只是 for 循环。我的日志猫说花色没有价值。当我运行它时,屏幕上没有任何内容。希望你能帮助我。

只需在第二个循环中将data更改为data2

        String url2 = "http://192.168.1.4/android_login_api/search_species_color.php?species_name=" + search_species;
        try {
            JSONArray data2 = new JSONArray(getHttpGet(url2));
            for(i = 0; i < data2.length(); i++){
                JSONObject c2 = data2.getJSONObject(i); // This line..
                map.put("color", c2.getString("flowercolor"));
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        }

最新更新