Skip to content

Commit

Permalink
Add Google Maps geocoding for event pages (#52)
Browse files Browse the repository at this point in the history
* Add Google Maps geocoding for event pages.

* Remove color.js
  • Loading branch information
FlyersPh9 authored Feb 21, 2024
1 parent d0bb63e commit 58f9492
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
44 changes: 23 additions & 21 deletions _includes/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,14 @@

<!-- Initialize Google Maps -->
<script>
let map;

function initMap() {
const location = { lat: -34.397, lng: 150.644 };
const map = new google.maps.Map(document.getElementById("map"), {
// Default location (fallback if geocoding fails)
const defaultLocation = { lat: -34.397, lng: 150.644 };
map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: location,
center: defaultLocation,
disableDefaultUI: true,
zoomControl: false,
mapTypeControl: false,
Expand All @@ -339,29 +342,28 @@
fullscreenControl: false,
});

const marker = new google.maps.Marker({
position: location,
map: map,
});
// Call the geocode function to update the map based on address
geocodeAddress("{{ page.location }}");
}
</script>

<!-- Pull average color from event image -->
<!-- TODO: Can we remove this? -->
<script>
document.addEventListener("DOMContentLoaded", function () {
const bannerEventSlides = document.querySelectorAll(".banner-event-slides");

bannerEventSlides.forEach((slide) => {
const slideImage = slide.querySelector("img");
if (slideImage) {
colorjs.average(slideImage.src).then((color) => {
const rgbColor = `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
slide.style.backgroundColor = rgbColor;
function geocodeAddress(address) {
const geocoder = new google.maps.Geocoder();

geocoder.geocode({ address: address }, function (results, status) {
if (status === "OK") {
// Center the map on the address location
map.setCenter(results[0].geometry.location);

// Add a marker at the address location
new google.maps.Marker({
map: map,
position: results[0].geometry.location,
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
}
</script>
{% endif %}

Expand Down
1 change: 0 additions & 1 deletion _layouts/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
content="{{ site.url }}/assets/video/events/{{ page.title | slugify }}.mp4"
/>
{% endif %}
<script src="https://unpkg.com/[email protected]/dist/color.js"></script>
<script
async
defer
Expand Down

0 comments on commit 58f9492

Please sign in to comment.