-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
218 lines (191 loc) · 8.43 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<!-- <link rel="stylesheet" type="text/css" href="master.css"> -->
</head>
<body>
<h1>My First Google Map</h1>
<div id="googleMap" style="width:60%;height:800px;"></div>
<script>
function detectBrowser() {
var useragent = navigator.userAgent;
var mapdiv = document.getElementById("map");
if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1) {
mapdiv.style.width = '100%';
mapdiv.style.height = '100%';
} else {
mapdiv.style.width = '600px';
mapdiv.style.height = '800px';
}
}
var myLatLng;
var latit;
var longit;
function geoSuccess(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
myLatLng = {
lat: latitude,
lng: longitude
};
var mapProp = {
// center: new google.maps.LatLng(latitude, longitude), // puts your current location at the centre of the map,
zoom: 15,
mapTypeId: 'roadmap',
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
//call renderer to display directions
directionsDisplay.setMap(map);
var bounds = new google.maps.LatLngBounds();
// var mapOptions = {
// mapTypeId: 'roadmap'
// };
// Multiple Markers
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'My location'
});
var markers = [
['3fe', 53.339964, -6.241972],
['The Fumbally', 53.337031, -6.272995],
['Coffeeangel', 53.343963, -6.262116],
['Brother Hubbard', 53.332744, -6.265639],
['Vice Coffee Inc.', 53.347829, -6.262295],
['Roasted Brown', 53.344813, -6.264707],
['Kaph', 53.342599, -6.263272],
['Fallon & Byrne', 53.343151, -6.263287],
['Clement & Pekoe', 53.341534, -6.26276],
['my current location', latitude, longitude]
];
// Info Window Content
var infoWindowContent = [
['<div class="info_content">' +
'<h3>3fe</h3>' +
'<p>32 Grand Canal Street Lower, Grand Canal Dock, Dublin 2</p>' +
'<img src="images/3fe.jpg" width="200" height="200">' +
'</div>'
],
['<div class="info_content">' +
'<h3>The Fumbally</h3>' +
'<p>Fumbally Lane, Dublin 8</p>' +
'<img src="images/thefumbally.jpg" width="200" height="200">' +
'</div>'
],
['<div class="info_content">' +
'<h3>' + markers[3][0] + '</h3>' +
'<p>46 Harrington Street Dublin 8</p>' +
'<img src="images/brotherhubbard.jpg" width="200" height="200">' +
'</div>'
],
['<div class="info_content">' +
'<h3>Vice Coffee inc</h3>' +
'<p>54 Middle Abbey St, Dublin 1</p>' +
'<img src="images/vicecoffeeinc.jpg" width="200" height="200">' +
'</div>'
],
['<div class="info_content">' +
'<h3>Roasted Brown</h3>' +
'<p>1st Floor, Filmbase, Curved Street, Temple Bar, Dublin 2</p>' +
'<img src="images/roastedbrown.jpg" width="200" height="200">' +
'</div>'
],
['<div class="info_content">' +
'<h3>Kaph</h3>' +
'<p>31 Drury St, Dublin 2</p>' +
'<img src="images/kaph-6.jpg" width="200" height="200">' +
'</div>'
],
['<div class="info_content">' +
'<h3>Fallon & Byrne</h3>' +
'<p>17 Exchequer St, Dublin 2</p>' +
'<img src="images/fallonandbyrne.jpg" width="200" height="200">' +
'</div>'
],
['<div class="info_content">' +
'<h3>Clement & Pekoe</h3>' +
'<p>50 South William St, Dublin 2</p>' +
'<img src="images/ClementPekoe.jpg" width="200" height="200">' +
'</div>'
]
];
// Display multiple markers on a map
var infoWindow = new google.maps.InfoWindow(),
marker, i;
// Loop through our array of markers & place each one on the map
for (i = 0; i < markers.length; i++) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0]
});
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(infoWindowContent[i][0]);
infoWindow.open(map, marker);
latit = marker.getPosition().lat();
longit = marker.getPosition().lng();
// console.log("lat: " + latit);
// console.log("lng: " + longit);
}
})(marker, i));
marker.addListener('click', function() {
directionsService.route({
// origin: document.getElementById('start').value,
origin: myLatLng,
// destination: marker.getPosition(),
destination: {
lat: latit,
lng: longit
},
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
});
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
}
}
// function calculateAndDisplayRoute(directionsService, directionsDisplay) {
// directionsService.route({
// // origin: document.getElementById('start').value,
// origin: myLatLng,
// destination: marker.getPosition(),
// travelMode: 'DRIVING'
// }, function(response, status) {
// if (status === 'OK') {
// console.log('all good');
// directionsDisplay.setDirections(response);
// } else {
// window.alert('Directions request failed due to ' + status);
// }
// });
// }
function geoError() {
alert("Geocoder failed.");
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
// alert("Geolocation is supported by this browser.");
} else {
alert("Geolocation is not supported by this browser.");
}
}
</script>
<script async src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCc7FZQ6jG2VcxnxbMNdkPFFzrUsJxq-ys&callback=getLocation"></script>
</body>
</html>