Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Maps Problem #68

Closed
MZain-ul-Abideen opened this issue Nov 15, 2024 · 1 comment
Closed

Google Maps Problem #68

MZain-ul-Abideen opened this issue Nov 15, 2024 · 1 comment

Comments

@MZain-ul-Abideen
Copy link

MZain-ul-Abideen commented Nov 15, 2024

Describe the Bug
The Google Maps integration on the http://localhost:8080/#/maps page does not work as expected. The map fails to render, and the browser console logs multiple errors related to the Google Maps API key and improper API loading patterns. The issue prevents users from interacting with the embedded map, resulting in a broken feature.

Steps to Reproduce

  1. Clone the repository and follow the setup instructions to run the project locally.
  2. Start the application using the provided instructions (e.g., npm run serve or equivalent command).
  3. Navigate to the Maps section at http://localhost:8080/#/maps.
  4. Open the browser's developer console (press F12 or right-click and choose Inspect, then go to the Console tab).
  5. Observe the following:
  • The map fails to load.
    
  • Errors related to the Google Maps API key and incorrect script loading patterns appear in the console.
    

Expected Behavior

  • The Google Map should load seamlessly on the Maps page, displaying the expected geographical content.
  • The console should not show any errors related to the API key or loading patterns.
  • The user should be able to interact with the map as intended (e.g., zoom, pan, click markers).

Actual Behavior
The Maps page fails to load the Google Map, and the console displays errors indicating a missing or invalid Google Maps API key.
{{
Google Maps JavaScript API has been loaded directly without loading=async. This can result in suboptimal performance. For best-practice loading patterns please see https://goo.gle/js-api-loading

[Vue warn]: Error in mounted hook: "TypeError: window.google.maps.marker is undefined"

found in

---> at src/pages/Maps.vue

at src/layout/dashboard/Content.vue
at src/layout/dashboard/DashboardLayout.vue
at src/App.vue

}}

Screenshots
Screenshot from 2024-11-15 18-06-57

Environment
Browser: Firefox (latest version)
Operating System: Manjaro Linux
Node.js Version: 10.9.0

Possible Causes

  1. Invalid or Missing API Key: The key provided for Google Maps might be incorrect, expired, or improperly configured in the project.
    
  2. Improper API Loading Pattern: The Google Maps JavaScript API has been loaded directly without using the recommended async attribute, leading to potential initialization issues.
    
  3. Integration Issue: The codebase might reference window.google.maps.marker incorrectly, or the relevant Google Maps library component (e.g., Marker) may not be loaded.
    

Proposed Solutions

  1. API Key Configuration:
    
  •     Verify the Google Maps API key in the project configuration file or .env file.
    
  1.     Ensure the API key is authorized for the domain localhost in the Google Cloud Console.
    
  •  Best Practice Loading:
    
  1.     Update the script tag for the Google Maps API to include the async and defer attributes:
    
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>
  • Follow the official documentation for optimal API loading: Google Maps JavaScript API Loading.

Debug Integration Code

  • Check the mounted hook in src/pages/Maps.vue for issues referencing window.google.maps.marker.
    
  • Ensure all necessary Google Maps components are explicitly loaded in the API script URL (e.g., libraries=places,geometry).
    

Additional Context

  • The problem may stem from incorrect integration of the Google Maps API with Vue's lifecycle methods, especially in the mounted hook.
    
  • Consult relevant documentation for the Google Maps API and Vue.js best practices when working with third-party libraries.
    
Copy link

@MZain-ul-Abideen this issue was automatically closed because it did not follow the bellow rules:

IMPORTANT: Please use the following link to create a new issue:

https://www.creative-tim.com/new-issue/vue-black-dashboard

**If your issue was not created using the app above, it will be closed immediately.**



Love Creative Tim? Do you need Angular, React, Vuejs or HTML? You can visit:
👉  https://www.creative-tim.com/bundles
👉  https://www.creative-tim.com


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant