forked from UpInside/play_google_maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
170 lines (150 loc) · 6.74 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
166
167
168
169
170
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>UpInside Play: Google Maps API</title>
<style>
body{
padding: 30px 20%;
}
#map {
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
max-width: 100%;
background-color: grey;
}
.locations{
display: block;
margin-top: 20px;
}
.locations_item{
display: inline-block;
font-size: 0.875em;
cursor: pointer;
padding: 10px;
margin: 10px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div id="map"></div>
<div class="locations">
<?php
require '../Source/Models/GoogleMaps.php';
$maps = new Source\Models\GoogleMaps;
$fpolis = clone $maps;
$fpolis->setAddress("Florianópolis");
echo "<span class='locations_item' data-location='{$fpolis->getAddress()}|{$fpolis->getLatLng()->lat}|{$fpolis->getLatLng()->lng}'>{$fpolis->getAddress()}</span>";
$morro = clone $maps;
$morro->setAddress("Morro das Pedras, Florianópolis");
echo "<span class='locations_item' data-location='{$morro->getAddress()}|{$morro->getLatLng()->lat}|{$morro->getLatLng()->lng}'>{$morro->getAddress()}</span>";
$lagoa = clone $maps;
$lagoa->setAddress("Lagoa da Conceição, Florianópolis");
echo "<span class='locations_item' data-location='{$lagoa->getAddress()}|{$lagoa->getLatLng()->lat}|{$lagoa->getLatLng()->lng}'>{$lagoa->getAddress()}</span>";
$campeche = clone $maps;
$campeche->setAddress("Campeche, Florianópolis");
echo "<span class='locations_item' data-location='{$campeche->getAddress()}|{$campeche->getLatLng()->lat}|{$campeche->getLatLng()->lng}'>{$campeche->getAddress()}</span>";
$canas = clone $maps;
$canas->setAddress("Canasvieiras, Florianópolis");
echo "<span class='locations_item' data-location='{$canas->getAddress()}|{$canas->getLatLng()->lat}|{$canas->getLatLng()->lng}'>{$canas->getAddress()}</span>";
echo "<span class='locations_item' data-location='"
. "{$fpolis->getAddress()}|{$fpolis->getLatLng()->lat}|{$fpolis->getLatLng()->lng} ||"
. "{$morro->getAddress()}|{$morro->getLatLng()->lat}|{$morro->getLatLng()->lng} ||"
. "{$lagoa->getAddress()}|{$lagoa->getLatLng()->lat}|{$lagoa->getLatLng()->lng} ||"
. "{$campeche->getAddress()}|{$campeche->getLatLng()->lat}|{$campeche->getLatLng()->lng} ||"
. "{$canas->getAddress()}|{$canas->getLatLng()->lat}|{$morro->getLatLng()->lng}"
. "'>Todos em Floripa</span>";
?>
</div>
<script src="jquery-3.2.1.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=SUA_KEY_AQUI"></script>
<script>
$(function () {
//localizações
var locations = [
{
title: "Rua Huberto Rohden, 100<br>Fpolis/SC",
lat: -27.6720101,
lng: -48.5054769,
icon: 'images/loc.png'
},
{
title: "Avenida Pequeno Príncipe, 800<br>Fpolis/SC",
lat: -27.6763079,
lng: -48.5005945,
icon: 'images/loc.png'
},
{
title: "Avenida Campeche, 2600<br>Fpolis/SC",
lat: -27.6657834,
lng: -48.4809122,
icon: 'images/loc.png'
}
];
function getMap(locations) {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 1,
center: locations[0]
});
//map center
var bounds = new google.maps.LatLngBounds();
//cria marcas
locations.map(function (location) {
var marker = new google.maps.Marker({
animation: google.maps.Animation.DROP,
position: location,
icon: location.icon,
map: map
});
locationInfo(marker, location.title);
bounds.extend(marker.position);
});
map.fitBounds(bounds);
var zoom = map.getZoom();
map.setZoom(zoom > 15 ? 15 : zoom);
}
getMap(locations);
function locationInfo(marker, content) {
var info = new google.maps.InfoWindow({
content: content
});
marker.addListener("click", function () {
info.open(marker.get('map'), marker);
});
}
$(".locations_item").click(function () {
var location = $(this).attr("data-location");
if (location.indexOf("||") >= 1) {
var setGroup = location.split("||");
var groupLocation = [];
setGroup.map(function (getLoc) {
var setLoc = getLoc.split("|");
groupLocation.push({
title: setLoc[0],
lat: parseFloat(setLoc[1]),
lng: parseFloat(setLoc[2]),
icon: "images/loc.png"
});
});
getMap(groupLocation);
} else {
var setLoc = location.split("|");
var newLoc = [
{
title: setLoc[0],
lat: parseFloat(setLoc[1]),
lng: parseFloat(setLoc[2]),
icon: "images/loc.png"
}
];
getMap(newLoc);
}
});
});
</script>
</body>
</html>