-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
130 lines (114 loc) · 3.71 KB
/
map.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
/**
* Google Maps demo for Kaipi.me's soline API
*
* Authors:
* - Ronald Cruz.
* - Ricardo Arcos.
*/
function initialize() {
var latlng = new google.maps.LatLng(-33.397968, -70.581037);
var myOptions = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
return new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
$(document).ready(function() {
var map = initialize();
var markers = new Array();
var key = 'bbac3c8fcd408dc8702047e7bead24ddb5af18211c2c0b2ad078f4eae307d6b6';
var infoWindow = new google.maps.InfoWindow;
$('#comunas').change(function(){
loadStations({'comuna': $(this).val()});
});
$.ajax({
url: 'http://kaipi.me/gasoline/counties?api_key=' + key,
dataType: 'json',
success: function(data) {
$.each(data.counties, function(index, county) {
var option = '<option value="' + county.id + '">' + county.name + '</option>';
$('#comunas').append(option);
})
}
});
function loadStations(filtro) {
var param = '';
if (filtro.comuna > 0){
param += '&county_id='+filtro.comuna;
}
for (i in markers){
markers[i].setMap(null);
}
markers = new Array();
$.ajax({
url : 'http://kaipi.me/gasoline/stations?api_key=' + key + param,
dataType: 'json',
success: function(stations) {
var southWest = null;
var northEast = null;
$.each(stations.stations, function(index, station) {
var latLng = new google.maps.LatLng(station.lat, station.lng);
var marker = new google.maps.Marker({'position': latLng, 'map': map});
markers.push(marker);
var html = '<div style="width: 400px, height: 200px"><strong>Dirección: ' + station.address + '</strong>';
html += '<div>93 Oct: $ ' + station.price_93 + '</div>';
html += '<div>95 Oct: $ ' + station.price_95 + '</div>';
html += '<div>97 Oct: $ ' + station.price_97 + '</div>';
html += '<div>Diesel: $ ' + station.price_diesel + '</div></div>';
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
southWest = getSouthWest(southWest, latLng);
northEast = getNorthEast(northEast, latLng);
})
var myLatLngBounds = new google.maps.LatLngBounds(southWest, northEast);
map.fitBounds(myLatLngBounds);
map.setCenter(myLatLngBounds.getCenter());
}
})
}
});
function getSouthWest(coordinates1, coordinates2) {
if (coordinates1 == null && coordinates2 == null) {
return null;
} else if (coordinates1 != null && coordinates2 == null) {
return coordinates1;
} else if (coordinates1 == null && coordinates2 != null) {
return coordinates2;
} else {
var latlng = new google.maps.LatLng(Math.min(coordinates1.lat(), coordinates2.lat()), Math.min(coordinates1.lng(), coordinates2.lng()));
return latlng;
}
}
function getNorthEast(coordinates1, coordinates2) {
if (coordinates1 == null && coordinates2 == null) {
return null;
} else if (coordinates1 != null && coordinates2 == null) {
return coordinates1;
} else if (coordinates1 == null && coordinates2 != null) {
return coordinates2;
} else {
var latlng = new google.maps.LatLng(Math.max(coordinates1.lat(), coordinates2.lat()), Math.max(coordinates1.lng(), coordinates2.lng()));
return latlng;
}
}
</script>
</head>
<body>
<div id="filtros">
<select id="comunas">
<option value="-1">Todas</option>
</select>
</div>
<div id="map_canvas" style="width:400px; height:700px">
</div>
</body>
</html>