inocan-group / vue3-google-map

A set of composable components for easy use of Google Maps in your Vue 3 projects.
https://vue3-google-map.com
MIT License
296 stars 60 forks source link

How can I use vue3-google-map with Nuxt 3 ? #272

Closed DDD5677 closed 3 months ago

DDD5677 commented 3 months ago

In console this error image

DDD5677 commented 3 months ago

In plugins folder vue-google-maps.ts file

import { defineNuxtPlugin } from "#app";

import VueGoogleMaps from "vue3-google-map";

export default defineNuxtPlugin((nuxtApp) => {
   const config = useRuntimeConfig();
   nuxtApp.vueApp.use(VueGoogleMaps as any, {
      load: {
         key: config.googleApi,
         libraries: "places",
      },
   });
});

In nuxt.config.ts

export default defineNuxtConfig({
   compatibilityDate: "2024-04-03",
   devtools: { enabled: false },
   css: ["~/assets/css/main.css"],
   runtimeConfig: {
      googleApi: process.env.GOOGLE_API_KEY, 
   },
   plugins: ["@/plugins/vue-google-maps"],
});

In my component

<template>
    <GoogleMap :api-key="config.googleApi" style="width: 100%; height: 500px" :center="center" :zoom="15">
        <Marker :options="{ position: center }" />
    </GoogleMap>
</template>

<script setup lang="ts">
import { GoogleMap, Marker } from 'vue3-google-map'
const config = useRuntimeConfig();
const center = { lat: 35, lng: -95 }
</script>