2017-11-14 2 views
1

내 데이터베이스의 색상에 따라지도에서 마커 색상을 변경하고 싶습니다. Idk이 내 코드에 무엇이 잘못된지 전혀 오류가 없습니다. 나는 그것이 for loop이지만 Idk는 올바른 논리가 무엇인지 생각한다.Android Studio Google지도 변경 마커 색상

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 루프. 내 logcat은 flowercolor에 대한 가치가 없다고 말합니다. 실행하면 아무 것도 화면에 표시되지 않습니다. 희망이 나를 도울 수 있습니다.

답변

0

단순히 두 번째 루프에서 data2data을 변경

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