Vue Google Maps - The JavaScript API encountered an error with loading from Google Maps: NotLoadingAPIFromGoogleMaps

Hello, I am currently facing an issue trying to add my API key to my Google map. Initially, everything worked fine when I used the string version of the key. However, I prefer to keep the key in my .env file. When I made this change, I encountered the Google Maps JavaScript API error: NotLoadingAPIFromGoogleMapsError. Any assistance on this matter would be greatly appreciated! Thank you.

*Edit: Upon further inspection, I have realized that the problem arises when attempting to load the API key from my .env file. The map loads successfully when I replace the line with process.env.VUE_APP_GOOOGLEMAPS_KEY; and input the actual API key.

MapPage.vue

    <template>
  <ion-page>
    <ion-header>
      <ion-toolbar>
        <ion-title>Map</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content :fullscreen="true">
      <GoogleMap :api-key="API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="15">
        <Marker :options="{ position: center }" />
      </GoogleMap>
    </ion-content>
  </ion-page>
</template>

<script lang="ts">
import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/vue';
import { GoogleMap, Marker } from "vue3-google-map";

export default {
  name: 'MapPage',
  components: { IonHeader, IonToolbar, IonTitle, IonContent, IonPage, GoogleMap, Marker },
  setup() {
    const center = { lat: 40.689247, lng: -74.044502 };
    const API_KEY = process.env.VUE_APP_GOOOGLEMAPS_KEY;

    return { center,API_KEY };
  },
};
</script>

Answer №1

Error Loading Google Maps API

Make sure to download the Maps JavaScript API directly from Google's servers. The script element responsible for loading the Maps JavaScript API is not correctly included on your page. For the API to function properly, it must be loaded directly from

https://maps.googleapis.com.

Refer to the guide on how to load the Maps JavaScript API.

https://developers.google.com/maps/documentation/javascript

This issue may also occur when using the old location for the google maps API (which used to work fine):

To resolve this, switch to the new location as indicated in the documentation:

https://maps.googleapis.com/maps/api/js

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

Using Regular Expressions in JavaScript to verify if an element from an array is contained within a string

Looking for a simple JavaScript code for a Vue application that will split the string into an array and check if any value is present in a different string. Here's what I have: let AffiliationString = " This person goes to Stony Brook" ...

Embedding Facebook data into an HTML document

While I am able to retrieve data from Facebook and display it on the console, I am facing issues when trying to display it on an HTML page. I attempted using: $("#mydiv").text(data); or $("#mydiv").append(data); However, this displays [object Object] ...

A guide on testing mouse clientY in React using JEST for effective testing

useEffect(() => { const mouseHandler = (event: MouseEvent) => { menuData.forEach((element) => { if (element.hasActiveDropdown && event.clientY > 50) { handleCloseDropDown(); // handleDropDown('0') ...

Material-UI Autocomplete can only save and display one specific property of an object at a time

Can someone help me with implementing Autocomplete from Material-UI? I want to store only a specific property value and not the entire object. For example, let's say I want to store the property Value, but it could be any other property as well. con ...

The error message "indexOf of undefined" appears when trying to read a property that does not exist within a new

Help Needed: The following error is happening: Cannot read property 'indexOf' of undefined at new HttpRequest (http.js:653) at HttpClient.request (http.js:1069) at HttpClient.get (http.js:1157) This occurs when I use the get() method from Ht ...

Constructing a hierarchical tree structure using an array of objects that are initially flat

My goal is to create a hierarchical tree structure from a flat array: The original flat array looks like this: nodes = [ {id: 1, pid: 0, name: "kpittu"}, {id: 2, pid: 0, name: "news"}, {id: 3, pid: 0, name: "menu"}, {id: 4, pid: 3, name: ...

Nodemailer fails to display an error message when the email is not successfully sent

I am currently working on implementing nodemailer for sending emails. However, I noticed that if the email address in the "to" field is incorrect, the email is not sent as expected. The issue is that there is no error displayed and the function still resol ...

What is the process for downloading an image in MobileSafari?

I'm currently working on an iOS website and I am facing a challenge in retrieving recently copied images using JavaScript. When you press and hold your finger on an image within a website, a menu appears with options to either Save the image or Copy. ...

What are the possible reasons for the failure of JavaScript when called dynamically through Ajax?

I've always been a big supporter of the JavaScript code for sorting tables. It's incredibly effective. However, I recently encountered an issue while trying to make the sorting function work with Ajax. I have a div layer on my main page that fe ...

There was an error while parsing JSON on line 1, where it was expecting either a '{' or '[' to start the input

I've been struggling to extract data from my PHP array that is encoded using json_encode. I'm new to JQuery and have been attempting this for a few days without success. This code snippet is not producing the desired results: $.post('coord ...

What steps do I need to take to build this jump page?

Disclaimer: I have very little experience with coding. As a self-taught graphic designer, I have only managed to create a simple page that helps me store common phrases I use frequently throughout the day. It was quite a challenge for me. I am currently w ...

Only trigger the onclick event once

Can anyone assist me with a function? The onclick event only triggers once. launchTagManager: function(id) { console.log(document.getElementById('metadata_field_multiple_text_701889_options['+id+']')); document.getElementById( ...

Leveraging jQuery's .animate method to create engaging search box animations

Greetings esteemed individuals... I am currently working on enhancing the search component for my application... http://jsfiddle.net/SkyKOG/K8utq/24/ input{ display:none; width:0px; color:#999; } Initially, I only had a simple search box so ...

The Bootstrap tree structure fails to display the tree

I am having trouble getting the bootstrap treeview to work (https://github.com/jonmiles/bootstrap-treeview). This is new to me and despite following all the steps, it's not functioning as expected. I believe I have included all the necessary details ...

Determination of the winner in a tic tac toe game is not accurate using the if statement

I need some help with an issue I'm having with my code involving the "if statement". I am trying to complete my tic-tac-toe game by writing a function that determines the winner of the game. The problem arises when I try to compare the content of spec ...

What is the best way to retrieve properties from a different module in JavaScript?

I have a module named ProgressIndicator: ... export default class ProgressIndicator { constructor() { ... const indicatorGeometry = new THREE.PlaneGeometry(2, 2, 1, 1) const indicatorMaterial = new THREE.ShaderMate ...

Utilizing the no-data-text attribute in v-combobox with Vuetify: Tips and tricks

My application includes a simple combobox, and I am trying to set a default text message to display when there are no entries in the items props. To achieve this goal, I utilized the no-data-text prop by passing a specific variable to it. <v-combobox ...

Refreshing the page causes Material UI Button to revert to default styling

My question regarding the Material UI Button losing styling after a page refresh (link: Material UI Button loses Styling after page refresh) went unanswered, so I am reposting with a CodeSandbox included for reference: https://codesandbox.io/s/bold-resonan ...

How can I prevent users from selecting text when they right click using JavaScript?

My custom context menu on canvas works well, but I'm facing an issue with Text elements. When I try to right-click on a text element, it triggers text selection as if double-clicking. I attempted to use the following code: document.addEventListener(& ...

Creating variables in JavaScript for background positions can be done by utilizing the backgroundPosition property

I'm a beginner in programming and I'm currently working on creating a variable for my background-position in Javascript/CSS. A developer friend of mine initially wrote the code, but I'm having difficulty assigning my background-position to a ...