* Load Google Maps API dynamically * @param {string} apiKey - The Google Maps API key * @returns {Promise} Promise that resolves when API is loaded
(apiKey)
| 64 | * @returns {Promise} Promise that resolves when API is loaded |
| 65 | */ |
| 66 | static loadGoogleMapsAPI(apiKey) { |
| 67 | return new Promise((resolve, reject) => { |
| 68 | // Check if already loading |
| 69 | if (window.googleMapsAPILoading) { |
| 70 | // Wait for existing load to complete |
| 71 | const checkInterval = setInterval(() => { |
| 72 | if (typeof google !== "undefined" && google.maps) { |
| 73 | clearInterval(checkInterval); |
| 74 | resolve(); |
| 75 | } |
| 76 | }, 100); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | window.googleMapsAPILoading = true; |
| 81 | |
| 82 | // Create script element |
| 83 | const script = document.createElement("script"); |
| 84 | script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places`; |
| 85 | script.async = true; |
| 86 | script.defer = true; |
| 87 | |
| 88 | script.onload = () => { |
| 89 | window.googleMapsAPILoading = false; |
| 90 | resolve(); |
| 91 | }; |
| 92 | |
| 93 | script.onerror = () => { |
| 94 | window.googleMapsAPILoading = false; |
| 95 | reject(new Error("Failed to load Google Maps API")); |
| 96 | }; |
| 97 | |
| 98 | document.head.appendChild(script); |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Create the Google Map with markers |
no outgoing calls
no test coverage detected