-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
86 lines (65 loc) · 2.53 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!doctype html>
<html>
<head>
<title>Zip Code Map</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?&key=[PUT YOUR KEY HERE]"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript">
//http://bl.ocks.org/mbostock/899711
//https://developers.google.com/maps/articles/toomanymarkers
//run python -m SimpleHTTPServer 8000 to view
var map = ""; // create a map variable, with Global scope.
var markersArray = []; // create array to hold markers
var data;
function initialize() {
geocoder = new google.maps.Geocoder();
// setup some options
var mapCenterLatLong = new google.maps.LatLng(39.8282, -98.5795);
var mapOptions = {
center: mapCenterLatLong,
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// create the map, in the DIV defined, using the options set just above.
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
// create the markers
getData();
}
function codeAddress(zipCode) {
geocoder.geocode({
'address': zipCode
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var lat = results[0].geometry.location.lat();
var long = results[0].geometry.location.lng();
var myLatLong = new google.maps.LatLng(lat, long);
var marker = new google.maps.Marker({
position: myLatLong,
map: map,
});
markersArray.push(marker);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function getData() {
d3.csv("data/zips.csv", function (d) {
var data = d;
var x = 0;
setInterval(function () {
if (x < d.length) {
codeAddress(d[x]["zipcode"]);
//console.log(x);
} else return;
x++;
}, 600);
})
}
</script>
</head>
<body onload="initialize()">
<h1>Zip Code Map</h1>
<div id="map_canvas" style="width:1000px; height:600px;"></div>
</body>
</html>