-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
165 lines (149 loc) · 7.82 KB
/
index.php
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
require "get_request.php";
$json = GET("https://api.foursquare.com/v2/venues/search?v=20161016&near=Bergamo&query=pizza&intent=checkin&limit=50&client_id=4FPUXDWGSST25LCPB5CCFJWCCFYYCOAGOQCHGD43MTAP1DBV&client_secret=1DPIKHBYXLUFIJHBJ2S3APZ5NF1QY42XO3MTZARD5R5XT34M");
$resp_array = json_decode($json, true);
?>
<!DOCTYPE html>
<html>
<head>
<title>Pizzerie Bergamo</title>
<link rel="stylesheet" type="text/css" href="http://maestronim.altervista.org/Pizzerie/style19.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body onload="loadResults(true)">
<div class="container">
<div class="mapcontainer">
<div id="map"></div>
</div>
<div class="venuesbuttoncontainer">
<div class="venuescontainer">
<?php
$venues = $resp_array["response"]["venues"];
for($i=0;$i<count($venues);$i++)
{
$venues_info [] = array(
"id" => $venues[$i]["id"],
"name" => $venues[$i]["name"],
"coords" => array(
"lat" => $venues[$i]["location"]["lat"],
"lng" => $venues[$i]["location"]["lng"]
),
"address" => $venues[$i]["location"]["address"],
"checkins" => $venues[$i]["stats"]["checkinsCount"]
);
}
?>
</div>
</div>
</div>
<script>
<?php
echo "var venues_info = " . json_encode($venues_info) . ";";
?>
var currentVenue = 0;
var markers = [];
var MAP;
var precInfoWindow = null;
var precMarker = null;
function loadResults(init) {
for (i = 0; i < 10; i++) {
document.getElementsByClassName("venuescontainer")[0].innerHTML +=
"<div id=\"" + venues_info[currentVenue]["id"] + "\" class=\"venuecontainer\" onclick=\"openInfoWindow(this.id)\">" +
"<div class=\"index\">" + (currentVenue+1) + "</div>" +
"<div class=\"venuemeta\">" +
"<div class=\"venuenameaddress\">" +
"<div class=\"venuename\">" + venues_info[currentVenue]["name"] + "</div>" +
"<div class=\"venueaddress\">" + venues_info[currentVenue]["address"] + "</div>" +
"</div>" +
"<div class=\"venuecheckins\">Visite registrate: " + venues_info[currentVenue]["checkins"] + "</div>" +
"<hr class=\"myhr\">" +
"</div>" +
"</div>";
placeMarker(new google.maps.LatLng(parseFloat(venues_info[currentVenue]["coords"]["lat"]), parseFloat(venues_info[currentVenue]["coords"]["lng"])));
currentVenue++;
}
/*if(init == true) {
document.getElementsByClassName("container")[0].innerHTML +=
"<div class=\"button\">" +
"<input type=\"button\" onclick=\"loadResults(false)\" value=\"Carica altri risultati\" class=\"btn btn-primary btn-md\" style=\"margin-left:10%;\">" +
"</div>";
}*/
if(currentVenue >= 50) {
var child = document.getElementsByClassName("button")[0];
var parent = document.getElementsByClassName("container")[0];
parent.removeChild(child);
}
}
function myMap() {
var mapProp = {
center: new google.maps.LatLng(45.6947359, 9.6687071),
zoom: 10
};
MAP = new google.maps.Map(document.getElementById("map"), mapProp);
for (i = currentVenue; i < 10; i++) {
placeMarker(new google.maps.LatLng(parseFloat(venues_info[i]["coords"]["lat"]), parseFloat(venues_info[i]["coords"]["lng"])));
}
}
function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
animation: google.maps.Animation.DROP,
map: MAP
});
google.maps.event.addListener(marker,'click',function() {
if(precInfoWindow != null) {
precInfoWindow.close();
}
if(precMarker != null) {
precMarker.setAnimation(null);
}
for (i = 0; i < venues_info.length; i++) {
if(Number((parseFloat(venues_info[i]["coords"]["lat"])).toFixed(6)) == Number(parseFloat(marker.getPosition().lat()).toFixed(6)) &&
Number((parseFloat(venues_info[i]["coords"]["lng"])).toFixed(6)) == Number(parseFloat(marker.getPosition().lng()).toFixed(6))) {
var infowindow = new google.maps.InfoWindow({
content: venues_info[i]["name"] + "<br>Lat: " +
Number(parseFloat(marker.getPosition().lat()).toFixed(6)) + "<br>Lng: " +
Number(parseFloat(marker.getPosition().lng()).toFixed(6))
});
marker.setAnimation(google.maps.Animation.BOUNCE);
infowindow.open(MAP, marker);
var top = document.getElementById(venues_info[i]["id"]).offsetTop;
window.scrollTo(0, top);
precInfoWindow = infowindow;
precMarker = marker;
break;
}
}
});
markers.push(marker);
}
function openInfoWindow(id) {
if(precInfoWindow != null) {
precInfoWindow.close();
}
if(precMarker != null) {
precMarker.setAnimation(null);
}
for (i = 0; i < venues_info.length; i++) {
if(id.localeCompare(venues_info[i]["id"]) == 0) {
var infowindow = new google.maps.InfoWindow({
content: venues_info[i]["name"] + "<br>Lat: " +
Number((parseFloat(venues_info[i]["coords"]["lat"])).toFixed(6)) + "<br>Lng: " +
Number((parseFloat(venues_info[i]["coords"]["lng"])).toFixed(6))
});
markers[i].setAnimation(google.maps.Animation.BOUNCE);
infowindow.open(MAP, markers[i]);
precInfoWindow = infowindow;
precMarker = markers[i];
break;
}
}
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCegvSr3HlEm1VmCEZL1SBrDsqAbVOaIwY&callback=myMap"></script>
</body>
</html>