Stop the repeated loading in Vue.js by implementing load-google-maps-api to ensure the map is only loaded

I am trying to dynamically load two instances of Google Maps on a single page but I keep encountering the following errors:

You have included the Google Maps JavaScript API multiple times on this page. This may result in unexpected errors.

Below is the code snippet for more assistance, using the load-google-maps-api node_module:


 googleMapInit () {

            let self = this,
                mapElement = this.$refs.canvasy;

            loadGoogleMapsAPI({
                key: this.gmk,
                language: this.language
            })
            .then( googleApi => {

                self.contextMarkerLatLng = new google.maps.LatLng( self.contextMarkerCoords.lat, self.contextMarkerCoords.lng );

                self.googleMap = new google.maps.Map( mapElement , {
                    disableDefaultUI: true,
                    styles: MapStylesObj.styles,
                    zoom: self.googleMapZoom,
                    minZoom: self.googleMapMinZoom,
                    center: self.contextMarkerLatLng
                });

Answer №1

Have you considered utilizing load-google-maps-api-2 for your project?

Check out load-google-maps-api-2 on npm

This package is based on load-google-maps-api and offers similar functionality with an additional feature:

It now includes a check to prevent API from loading multiple times, which helps avoid console warnings from Google API.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leverage dependency injection with vue / vitest to enhance modularity and

My Software Configuration Developing a Vue 3 application Utilizing Pinia stores Initiating a plugin in my main.ts by using app.use(myPlugin) Creating and providing a repository (MyRepo) in MyPlugin.ts based on specific environment conditions. This reposi ...

Retrieving JSON data using JavaScript

'[{"SponsorID":382,"SponsorName":"Test Name","MonthEndReport":true,"AccountingManager":"Me","UnboundProperties":[],"State":16}]' When attempting to retrieve the information above with the following code: for (var i = 0; i < data.length; i++) ...

Retrieve data from the table and dropdown menu by clicking a button

A script is in place that retrieves data from two columns (Members, Description) dynamically from the table upon button click. Table html Here is the JQuery code responsible for extracting values from the table: $(function() { $('#myButton') ...

Display Quantity of Current Website Visitors

Similar Question: how to track website visitors using java script or php I am looking to retrieve the current number of viewers on a webpage that has an embedded stream. Is there a method to accomplish this utilizing PHP and AJAX, in order to display ...

Basic AngularJS framework with minimal external dependencies

I have been searching for an AngularJS skeleton to set up my project, but it seems like all the skeletons I find online require the installation of numerous dependencies through npm and/or bower. Due to security concerns at the firm where I am working on ...

Exploring the functionality of jQuery's html() method through multiple interactions

I am currently experimenting with this demo. I'm investigating why the HTML content disappears after using the second button. Everything works fine as long as you only click on btn #from-content-1 or only on #from-content-2. But if you click on #from ...

Ways to extract specific HTML from a jQuery element

When fetching html from a website, how can I extract specific html content instead of getting all of it? I have attempted the following method: Before appending data to the target below container.html(data); I would like to perform something like data.f ...

Using AngularJS to pass the output of a unique filter to another custom filter

I have successfully developed two custom filters and am attempting to utilize them both within an ng-repeat loop. Is there a way for me to pass the output of the first filter as an input for the second one? I attempted using 'as' keyword in ng- ...

Tips for sending textarea data via AJAX with TinyMCE

Recently, I encountered an issue with submitting forms using the TinyMCE Jquery plugin. While regular input fields like text fields and select boxes submit just fine, there seems to be a glitch when it comes to submitting a textarea with TinyMCE. It requir ...

The callback for fs.WriteFile is triggered before the file is written to disk

I am encountering an issue with my express request callback that involves writing a file after calling a callback function. zip.addLocalFolder(`/path/to/folder`, `./`); var data = zip.toBuffer(); fs.writeFile(`path/to/download.zip`,data,function (err) { ...

Order of Execution for Nested Promises

Curious about nested promises, I came across this coding challenge in my tutorials. Can someone shed some light on the execution order of this code? new Promise((resolve) => { new Promise((res) => { console.log("c"); resolve(3); ...

Search across the entire table in your React application with Global

Having trouble implementing global search with the new Material UI Next table component. I have a handleSearch method that takes an event as a parameter and uses regex to check if the event.target.value matches any data in the table. However, when I dele ...

Issue with Ajax submit button failing to pass ID

I am encountering an issue while trying to update data using bootstrap modal. When the CGridView selectionChanged event is triggered, it should call a function to display a modal dialog form and populate the form with the selected data. Below is my CGrid ...

What is preventing me from retrieving these JSON values?

One of the functionalities on my website involves making an AJAX call to retrieve a member's profile information for editing purposes. The code snippet responsible for this operation is shown below: function loadProfileData() { var ...

Utilizing DataLoader in tandem with Mongoose: A comprehensive guide

I am currently working on implementing DataLoader with Mongoose for the following use case: export const PurchaseOrderType = new GraphQLObjectType({ name: "PurchaseOrder", description: "PurchaseOrder", interfaces: () => [NodeInterface], ...

Vue.js: In a third-party library, the reference to "this" is coming back as "undefined"

My third-party script contains code in the following format ( function initialMethod(scope, factory) { // 'scope' is undefined when used in Vue // but it works fine in React and Angular } (this, function function1(param1) { ...

Acquiring a property from an object that is specified within a function

I have created an object with properties inside a function: function createObject() { const obj = { property1: value, property2: value } } How can I access this object from outside the function? Would redefining it like ...

Begin your meteor project with a remote MongoDB server on a Windows operating system

Currently tackling a project that requires me to integrate my meteor project with a remote MongoDB server on Windows. I successfully set the environment variable (MONGO_URL="DB LINK") from OSX using terminal commands, but I'm encountering difficulties ...

Dynamically updating Vue.js links based on component property values

In my Vue project's homepage, a series of Bootstrap cards need to contain hyperlink buttons that lead to URLs with a common base URL. The ending of each URL should be determined by the "name" property value of the prop associated with the card. For in ...

Require Google Chrome to show a blank page upon refresh

After reloading the page in either IE/Edge or Chrome/Firefox, I noticed a significant difference. IE/Edge clears the page and displays a white page, while Chrome/Firefox does not. I'm wondering if there is a way to use JavaScript to instruct Chrome/F ...