【问题标题】:Android Studio Google Map Change Marker ColorAndroid Studio 谷歌地图更改标记颜色
【发布时间】:2018-04-27 00:18:07
【问题描述】:

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

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循环。我的日志猫说花色没有价值。当我运行它时,我的屏幕上什么也没有出现。希望你能帮助我。

【问题讨论】:

    标签: php android sql json google-maps


    【解决方案1】:

    只需在第二个循环中将 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();
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-19
      • 2018-02-16
      • 2011-01-28
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      • 1970-01-01
      相关资源
      最近更新 更多