<script> // Function to initialize the map function initMap() { // Define map options var mapOptions = { center: { lat: 38.0, lng: -100.0 }, fullscreenControl: true, mapTypeControl: false, streetViewControl: false, zoom: 4, zoomControl: true, maxZoom: 17, mapId: "" };
// Initialize the map with options var map = new google.maps.Map(document.getElementById('map'), mapOptions);
// Select all elements with class "location-result" var locationResults = document.querySelectorAll('.location-result');
// Iterate over each location result locationResults.forEach(function(result) { // Extract latitude and longitude values from the result var latElement = result.querySelector('.coords_lat'); var lngElement = result.querySelector('.coords_lng');
// Check if latitude and longitude elements exist if (latElement && lngElement) { var lat = parseFloat(latElement.textContent); var lng = parseFloat(lngElement.textContent);
// Create a marker for each location var marker = new google.maps.Marker({ position: { lat: lat, lng: lng }, map: map });
// Add click event listener to each location result result.addEventListener('click', function() { // Pan the map to the clicked marker's position map.panTo({ lat: lat, lng: lng }); // Set zoom level to 1 map.setZoom(10); }); } }); }
// Function to check if the document is ready function checkDocumentReady() { if (document.readyState === 'complete') { // Document is already in complete state, call initMap directly initMap(); } else { // Document is not yet in complete state, wait for DOMContentLoaded event document.addEventListener('DOMContentLoaded', function() { // Call initMap when DOMContentLoaded event fires initMap(); }); } }
// Call checkDocumentReady to determine when to execute initMap checkDocumentReady();
for anyone following this conversation, this got resolved for google maps you don't need anything special, just define your initMap function and it will call it once script is loaded
","upvoteCount":0,"dateCreated":"2024-02-03T19:27:37.742Z","datePublished":"2024-02-03T19:27:37.742Z","dateModified":"2024-02-03T19:27:37.742Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#3bc00fc8-1057-4a96-a326-66e648f1d79f","author":{"@type":"Person","url":"https://help.webstudio.is/members/4909993b-8f86-4e28-b78d-3d611b93f9f4","name":"Dirky Dirk","identifier":"4909993b-8f86-4e28-b78d-3d611b93f9f4","image":"https://cdn.discordapp.com/avatars/338154523245805580/e2ec7f968aa1e5cbe861c52784271e08.webp?size=256"}},{"@type":"Answer","text":"so i did have the script in the project settings as well. which i just removed that.","upvoteCount":0,"dateCreated":"2024-02-03T19:28:17.747Z","datePublished":"2024-02-03T19:28:17.747Z","dateModified":"2024-02-03T19:28:17.747Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#20aaa242-7164-4fe0-9bc5-8b138bf5d032","author":{"@type":"Person","url":"https://help.webstudio.is/members/4909993b-8f86-4e28-b78d-3d611b93f9f4","name":"Dirky Dirk","identifier":"4909993b-8f86-4e28-b78d-3d611b93f9f4","image":"https://cdn.discordapp.com/avatars/338154523245805580/e2ec7f968aa1e5cbe861c52784271e08.webp?size=256"}},{"@type":"Answer","text":"","upvoteCount":0,"dateCreated":"2024-02-03T19:28:37.361Z","datePublished":"2024-02-03T19:28:37.361Z","dateModified":"2024-02-03T19:28:37.361Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#84811df4-5ecc-47a2-bf0b-47b1de01255b","author":{"@type":"Person","url":"https://help.webstudio.is/members/4909993b-8f86-4e28-b78d-3d611b93f9f4","name":"Dirky Dirk","identifier":"4909993b-8f86-4e28-b78d-3d611b93f9f4","image":"https://cdn.discordapp.com/avatars/338154523245805580/e2ec7f968aa1e5cbe861c52784271e08.webp?size=256"}},{"@type":"Answer","text":"can you share a link? when is the error happening?","upvoteCount":0,"dateCreated":"2024-02-03T19:29:04.833Z","datePublished":"2024-02-03T19:29:04.833Z","dateModified":"2024-02-03T19:29:04.833Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#5fe48ff6-9fa1-45c7-b851-ed3e2ecb3bd2","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"}},{"@type":"Answer","text":"Sure, i'll DM you an admin link so you can take a peak.","upvoteCount":0,"dateCreated":"2024-02-03T19:29:30.060Z","datePublished":"2024-02-03T19:29:30.060Z","dateModified":"2024-02-03T19:29:30.060Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#0743d028-1512-4ed6-8b3a-58d32ffd240e","author":{"@type":"Person","url":"https://help.webstudio.is/members/4909993b-8f86-4e28-b78d-3d611b93f9f4","name":"Dirky Dirk","identifier":"4909993b-8f86-4e28-b78d-3d611b93f9f4","image":"https://cdn.discordapp.com/avatars/338154523245805580/e2ec7f968aa1e5cbe861c52784271e08.webp?size=256"}},{"@type":"Answer","text":"it seems like there is some case wwhere you initMap() and google maps script hasn't loaded","upvoteCount":0,"dateCreated":"2024-02-03T19:29:42.773Z","datePublished":"2024-02-03T19:29:42.773Z","dateModified":"2024-02-03T19:29:42.773Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#e37e7c51-4719-4245-b4c4-49dc8fa26769","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"}},{"@type":"Answer","text":"I just sent you a DM with admin link if you don't mind taking a look","upvoteCount":0,"dateCreated":"2024-02-03T19:30:23.211Z","datePublished":"2024-02-03T19:30:23.211Z","dateModified":"2024-02-03T19:30:23.211Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#838c6a82-1676-45a7-9f09-d28dbae9056a","author":{"@type":"Person","url":"https://help.webstudio.is/members/4909993b-8f86-4e28-b78d-3d611b93f9f4","name":"Dirky Dirk","identifier":"4909993b-8f86-4e28-b78d-3d611b93f9f4","image":"https://cdn.discordapp.com/avatars/338154523245805580/e2ec7f968aa1e5cbe861c52784271e08.webp?size=256"}},{"@type":"Answer","text":"for anyone following this conversation, this got resolved for google maps you don't need anything special, just define your initMap function and it will call it once script is loaded","upvoteCount":0,"dateCreated":"2024-02-04T11:17:40.742Z","datePublished":"2024-02-04T11:17:40.742Z","dateModified":"2024-02-04T11:17:40.742Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#8ee3e02c-c1d7-4467-9c7b-4e8ed8c94ab6","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"}},{"@type":"Answer","text":"based on their docs https://developers.google.com/maps/documentation/javascript/load-maps-js-api","upvoteCount":0,"dateCreated":"2024-02-04T11:19:22.209Z","datePublished":"2024-02-04T11:19:22.209Z","dateModified":"2024-02-04T11:19:22.209Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#48680e56-1400-427e-91b0-a8a3efd7f5da","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"}},{"@type":"Answer","text":"thanks oleg!","upvoteCount":0,"dateCreated":"2024-02-04T18:27:17.242Z","datePublished":"2024-02-04T18:27:17.242Z","dateModified":"2024-02-04T18:27:17.242Z","url":"https://help.webstudio.is/troubleshooting-an-error-S7bbPJMrjS5m#99b01a81-0b03-43d1-8540-d9bb7bf16074","author":{"@type":"Person","url":"https://help.webstudio.is/members/4909993b-8f86-4e28-b78d-3d611b93f9f4","name":"Dirky Dirk","identifier":"4909993b-8f86-4e28-b78d-3d611b93f9f4","image":"https://cdn.discordapp.com/avatars/338154523245805580/e2ec7f968aa1e5cbe861c52784271e08.webp?size=256"}}]}}