Geocode.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script src="./libs/d3.v3.min.js"></script>
<script src="./libs/queue.js"></script>
<script src="./libs/topojson.js"></script>
<script type="text/javascript" src="./libs/jquery-1.11.1.min.js"></script>
<script src="./libs/FileSaver.js"></script>

<div id="vis"></div>


<script>



    d3.json("./data/CleanedData/cleaned_data_05.json",function(error,dataC){
//what does this line do? what is dataC? 
        d3.csv("./Seattle/SeattleSchools.csv",function(error,data){

            var bos = dataC["children"][0]["children"];
            

            $.each(bos,function(idC,arrayC){

               

                $.each(data,function(id,array){


                    if(parseInt(arrayC["name"]) == parseInt(array["Zipcode"]) ){

                        var locationString = array["Address"]+", "+array["Address2"]+", "+array["ZipCode"];

                        d3.json("https://maps.googleapis.com/maps/api/geocode/json?address="+locationString+"&sensor=true&key=AIzaSyAgj_OuV-myW1mb5XaNnZ7gvCpxN2jiW_E",function(res){

                            var obj = {}
                            obj["name"] = array["Business_Name"];
                            obj["type"] = array["Type_of_Business"];
                            obj["city"] = array["City"];

                            if(res.results[0]){

                                var lat = res.results[0].geometry.location.lat;
                                var long = res.results[0].geometry.location.lng;

                                obj["location"] = {"lat": lat, "lng":long};
                            }

                            $.each(arrayC["children"],function(id_c,array_c){
                                if(array_c["name"] == "Company"){
                                    array_c["children"].push(obj);
                                }
                            });


                            if(idC == bos.length-1 && id > data.length-944 ){
                                //console.log(dataC)
                                saveToFile(dataC,"cleaned_data_05.json");
                            }
                        });

                    }

                })


            });


        });

    });

    var saveToFile = function(object, filename){
        var blob, blobText;
        blobText = [JSON.stringify(object)];
        blob = new Blob(blobText, {
            type: "text/plain;charset=utf-8"
        });
        saveAs(blob, filename);
    }




</script>


</body>
</html>