-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogleMap.js
More file actions
38 lines (35 loc) · 1.17 KB
/
googleMap.js
File metadata and controls
38 lines (35 loc) · 1.17 KB
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
'use strict';
function mapMarker(event) {
googleMap();
var address = event.target.textContent;
var mapGeo = new google.maps.Geocoder();
for(var i = 0; i < allLocations.length; i++) {
if(address === allLocations[i].address) {
var locName = allLocations[i].name;
mapGeo.geocode( { 'address': address + ', Seattle, WA'}, function(results, status) {
if (status == 'OK') {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
});
var infowindow = new google.maps.InfoWindow({
content: locName + '</br>' + address
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
}
};
function showAddressMarker() {
var addressForMarker = document.querySelectorAll('.address');
for (var i = 0; i < addressForMarker.length; i++) {
addressForMarker[i].addEventListener('click', mapMarker);
}
};
showAddressMarker();