Reactive Vue 3 components for Google maps

Overview

Vue 3 Google maps Components

Set of mostly used Google Maps components for Vue.js.

Why this library exists?

We heavily use Google Maps in our projects, so I wanted to have a well maintained Google Maps library.

Documentation

Checkout vue-map.netlify.app for a detailed documentation or codesandbox for an example

Installation

You can install it using npm

npm install -S @fawmi/vue-google-maps

Basic usage

You need an API Key. Learn how to get an Api key .

Configure Vue to use the Components

In your main.js

import { createApp } from 'vue'
import  VueGoogleMaps from '@fawmi/vue-google-maps'

const app = createApp(App);
app.use(VueGoogleMaps, {
    load: {
        key: 'YOUR_API_KEY_COMES_HERE',
    },
}).mount('#app')

Use it anywhere in your components

<template>
  <GMapMap
      :center="{lat: 51.093048, lng: 6.842120}"
      :zoom="7"
      map-type-id="terrain"
      style="width: 100vw; height: 900px"
  >
  </GMapMap>
</template>

<script >
export default {
  name: 'App',
  data() {
    return {
      center: {lat: 51.093048, lng: 6.842120},
    }
  }
}
</script>

Components

Markers

If you need to add markers to the Map, add GMapMarker as child of GMapMap component.

<template>
  <GMapMap
      :center="center"
      :zoom="7"
      map-type-id="terrain"
      style="width: 500px; height: 300px"
  >
    <GMapMarker
        :key="marker.id"
        v-for="marker in markers"
        :position="marker.position"
    />
  </GMapMap>
</template>
<script>
export default {
  name: 'App',
  data() {
    return {
      center: {lat: 51.093048, lng: 6.842120},
      markers: [
        {
          id: 'dfsldjl3r',
          position: {
            lat: 51.093048, lng: 6.842120
          },
        }
      ]
    }
  }
}
</script>

Cluster

If you have too many markers, it is helpful to cluster markers. You can easily cluster markers by wrapping your markers with GMapCluster component.

<template>
  <GMapMap
      :center="center"
      :zoom="7"
      map-type-id="terrain"
      style="width: 500px; height: 300px"
  >
    <GMapCluster>
      <GMapMarker
          :key="index"
          v-for="(m, index) in markers"
          :position="m.position"
          :clickable="true"
          :draggable="true"
          @click="center=m.position"
      />
    </GMapCluster>
  </GMapMap>
</template>
<script>
export default {
  name: 'App',
  data() {
    return {
      center: {lat: 51.093048, lng: 6.842120},
      markers: [
        {
          position: {
            lat: 51.093048, lng: 6.842120
          },
        }
        , // Along list of clusters
      ]
    }
  }
}
</script>

Heatmap

If you need to add heatmap layer to the Map, add visualization library in load config and add GMapHeatmap as child of GMapMap component.

import { createApp } from 'vue'
import  VueGoogleMaps from '@fawmi/vue-google-maps'

const app = createApp(App);
app.use(VueGoogleMaps, {
  load: {
    key: 'YOUR_API_KEY_COMES_HERE',
    libraries: "visualization"
  },
}).mount('#app')
<template>
  <GMapMap
    ref="myMapRef"
    :center="center"
    :zoom="zoom"
    style="width: 100%; height: 600px"
  >
    <GMapHeatmap :data="heatData"></GMapHeatmap>
  </GMapMap>
</template>
<script>
export default {
  name: 'App',
  setup() {
    const center = {lat: 52.2985593, lng: 104.2455337}
    const zoom = 12
    const myMapRef = ref();
    const heatData = ref([])

    watch(myMapRef, googleMap => {
      if (googleMap) {
        googleMap.$mapPromise.then(map=> {
          heatData.value = [
            {location: new google.maps.LatLng({lat: 52.2985593, lng: 104.2455337})},
          ];
        })
      }
    });

    return {
      center,
      zoom,
      heatData,
      myMapRef
    }
  },
}
</script>

Checkout docs for more component

Access map object

If you want to access google map object, you can access it by getting ref of the map object.

<template>
  <GMapMap ref="myMapRef" />
</template>
<script>
export default {
  mounted() {
    console.log(this.$refs.myMapRef)
  }
}
</script>

Map options

You can pass Map options using options property:

See MapOptions for a complete list of available options.

<GMapMap
 :options="{
   zoomControl: true,
   mapTypeControl: false,
   scaleControl: false,
   streetViewControl: false,
   rotateControl: false,
   fullscreenControl: true,
   disableDefaultUi: false
 }"
>
</GMapMap>

More components

Many other components are also supported. Checkout docs for more.

Contributions

The best way to contribute is to report reproducible bugs, but feature requests and improvement suggestions are always welcome too. And definitely bug fixes and PR are welcome.

Comments
  • Event doesn't work

    Event doesn't work

    Describe the bug The events are not working except client event.

    To Reproduce Steps to reproduce the behavior:

    1. Add dragend into Marker something like <GMapMarker @dragend="getMarkerLocation" />

    Expected behavior getMarkerLocation function should be triggered if I drag the map pin

    Screenshots

    Desktop (please complete the following information):

    • OS: mac OS 10.14
    • Browser Chrome
    • Version 89.0

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context I check the code in node_modules and I don't think you add the lister for the events except click. This is original code in your library.

    inst.addListener('click', ()=> {
              this.$emit('click')
            });
    

    And I update the manually to fix the issue.

    inst.addListener('click', ()=> {
      this.$emit('click')
    });
    inst.addListener('dragend', (event)=> {
      this.$emit('dragend', event)
    });
    

    After I update, the function is triggered.

    I'd like you to check and update the modules and it would be helpful.

    Or if I did wrong, I'd like you to let me know the way to trigger the events without updating library.

    Thanks

    opened by domadev812 10
  • Vite produces error on import - marker-clusterer-plus does not provide an export named 'default'

    Vite produces error on import - marker-clusterer-plus does not provide an export named 'default'

    Describe the bug When using vite, the vite throws below error

    The requested module '/node_modules/marker-clusterer-plus/src/markerclusterer.js?v=9cd0e59f' does not provide an export named 'default'
    

    To Reproduce Steps to reproduce the behavior:

    1. Instantiate Vue project using vite
    2. Import library in main.js import VueGoogleMaps from '@fawmi/vue-google-maps'

    Expected behavior No error

    Screenshots

    image

    Desktop (please complete the following information):

    • OS: Windows
    • Browser: Chrome
    • Version: 92

    Additional context Should we move to using https://github.com/googlemaps/js-markerclustererplus instead of no longer maintained https://github.com/mikesaidani/marker-clusterer-plus

    opened by adarshmadrecha 5
  • Forwards closeclick event from InfoWindow to Vue event.

    Forwards closeclick event from InfoWindow to Vue event.

    I happened to notice that when using the close button on an InfoWindow or pressing escape, the closeclick event was not being emitted. This is because the closeclick event emitted by Google was not being listened to. This PR resolves that.

    opened by aidan-casey 5
  • Uncaught SyntaxError: The requested module '/node_modules/fast-deep-equal/index.js?v=b4f8fdde' does not provide an export named 'default' (at index.esm.js?v=b4f8fdde:1:8)

    Uncaught SyntaxError: The requested module '/node_modules/fast-deep-equal/index.js?v=b4f8fdde' does not provide an export named 'default' (at index.esm.js?v=b4f8fdde:1:8)

    As soon as I add import VueGoogleMaps from '@fawmi/vue-google-maps' in the main.js file, an error is shown and the app breaks.

    I already tried to remove and read the npm package. No success.

    opened by luciendub 4
  • Cluster icon moves with the map when panning

    Cluster icon moves with the map when panning

    When using marker cluster, when panning the map the cluster icon also pans along.

    Expected behavior The cluster icon stays when the markers originally were.

    Screenshots The cluster icon where it should be image

    On panning the map to a different location, the cluster icon pans along with the maps and moves. image

    Desktop (please complete the following information):

    • OS: Windows 11
    • Browser Google Chrome
    • Version 101.0.4951.54

    Additional context Code <GMapMap :options="options" :center="mapStore.currentPosition" :zoom="7" class="w-100 h-100"> <GMapCluster :styles="mapClusterStyles"> <GMapMarker v-for="(m, index) in markers" :key="index" :position="m.position" :clickable="true" :icon="'/images/map-marker.png'" @click="onMarkerClick(m)" > <GMapInfoWindow :closeclick="true" :opened="openedMarkerID === m.id" @closeclick="setOpenedMarker(null)" > <LocationInfo></LocationInfo> </GMapInfoWindow> </GMapMarker> </GMapCluster> </GMapMap > @fawmi/vue-google-maps version "^0.9.7",

    opened by pokhrelashok 4
  • Nuxt3:  fast-deep-equal does not provide an export named 'default'

    Nuxt3: fast-deep-equal does not provide an export named 'default'

    Describe the bug

    Error in development in chrome

    Uncaught SyntaxError: The requested module '/_nuxt/node_modules/fast-deep-equal/index.js?v=59f3ca57' does not provide an export named 'default'
    

    Causes my whole script tag to pause in development. But it transpiles and builds correctly in production environnement

    To Reproduce

    Steps to reproduce the behavior:

    1. Followed steps here
    2. And here
    3. Start project in development mode

    Expected behavior

    The page to load and all subsequent vue script to load

    Desktop (please complete the following information):**

    • Device: PC
    • OS: Windows 10
    • Browser Chrome
    • Version 106.0.5249.91
    opened by Blemming 3
  • Error when including Marker

    Error when including Marker

    I get this error but only when I add the GMapCluster/GMapMarker inside the GMapMap:

    mapElementMixin.js:26 Uncaught TypeError: this.$mapPromise.then is not a function at Proxy.provide (mapElementMixin.js:26) at applyOptions (VM5793 runtime-core.esm-bundler.js:5502)

    The code I'm using is currently identical (to the best of my knowledge) to what is used in the codesandbox example, including the 0.8.7 version. Can someone point me in the direction to resolve this issue?

    Thanks.

    opened by francisjavier 3
  • Custom Map style is not working

    Custom Map style is not working

    Hi dear! Thanks for creating for great plugin. I want to use silver theme of map. So I have used the suggested official site to create map styles. https://mapstyle.withgoogle.com/

    But when I apply it on GMapMap component, it doesn't take effect.

     <GMapMap 
                :zoom="15"
                :center="latlong"
                map-type-id="terrain"
                style="height: 200px"
                :style="gMapStyle"
            >
                <GMapMarker
                    :key="some.id"
                    :position="latlong"
                ></GMapMarker>
            </GMapMap>
    

    But result is same as show below image

    opened by afrazahmmad 3
  • Icon Size

    Icon Size

    Is your feature request related to a problem? Please describe. It’d be nice to be able to pass an icon object instead of just a url. That way we can size the icon for each marker.

    Describe the solution you'd like Expand the icon prop to handle and object or a string.

    opened by nathanaelphilip 3
  • Add the event parameters to the event wrappers

    Add the event parameters to the event wrappers

    This PR adds the Marker's event params to wrapped event listeners. The events like drag, dragend, ... have some arguments and they are required inside event listeners.

    opened by khalilst 3
  • Add documentation addition - adding libraries

    Add documentation addition - adding libraries

    Thanks for the library, it's really useful. In the docs, there is the autocomplete component, however to use this, you must add the places library when registering with vue. This is missing from the documentation, would be worth adding this - I'd have done it, but couldn't find the repo for the docs:

    To use the AutoComplete component, you must add the places API in the google console and add the library to the libraries array when registering with vue:

    const app = createApp(App);
    app.use(VueGoogleMaps, {
        load: {
            key: 'YOUR_API_KEY_COMES_HERE',
            libraries: ['places']
        },
    }).mount('#app')
    
    opened by Kyle123 3
  • Bump decode-uri-component from 0.2.0 to 0.2.2 in /docs

    Bump decode-uri-component from 0.2.0 to 0.2.2 in /docs

    Bumps decode-uri-component from 0.2.0 to 0.2.2.

    Release notes

    Sourced from decode-uri-component's releases.

    v0.2.2

    • Prevent overwriting previously decoded tokens 980e0bf

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2

    v0.2.1

    • Switch to GitHub workflows 76abc93
    • Fix issue where decode throws - fixes #6 746ca5d
    • Update license (#1) 486d7e2
    • Tidelift tasks a650457
    • Meta tweaks 66e1c28

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the Security Alerts page.
    dependencies 
    opened by dependabot[bot] 1
  • Error with Nuxt3: does not provide an export named 'default'

    Error with Nuxt3: does not provide an export named 'default'

    With Nuxt3 installing the plugin like this: https://github.com/fawmi/vue-google-maps#nuxt-3-usage I get this error: The requested module '/_nuxt/node_modules/fast-deep-equal/index.js?v=53c762e2' does not provide an export named 'default'

    What I'm doing wrong?

    opened by mcamprodon 4
  • Bump loader-utils from 1.4.0 to 1.4.2

    Bump loader-utils from 1.4.0 to 1.4.2

    Bumps loader-utils from 1.4.0 to 1.4.2.

    Release notes

    Sourced from loader-utils's releases.

    v1.4.2

    1.4.2 (2022-11-11)

    Bug Fixes

    v1.4.1

    1.4.1 (2022-11-07)

    Bug Fixes

    Changelog

    Sourced from loader-utils's changelog.

    1.4.2 (2022-11-11)

    Bug Fixes

    1.4.1 (2022-11-07)

    Bug Fixes

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the Security Alerts page.
    dependencies 
    opened by dependabot[bot] 1
  • Clustering issue.

    Clustering issue.

    Hello,

    Having an issue with clustering GMapCluster Trying to cluster markers but its doesn't seem to work here a snapshot of my console

    bindProps.js?v=08c62b4d:32 Uncaught (in promise) Error: setMaxZoom is not a method of (the Maps object corresponding to) undefined
        at bindProps (bindProps.js?v=08c62b4d:32:13)
        at build-component.js?v=08c62b4d:108:11
    

    And

    cluster.vue:101 Uncaught (in promise) TypeError: this.$clusterObject.repaint is not a function
        at Proxy.updated (cluster.vue:101:27)
        at runtime-core.esm-bundler.js:2723:40
        at callWithErrorHandling (runtime-core.esm-bundler.js:155:22)
        at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:164:21)
        at hook.__weh.hook.__weh (runtime-core.esm-bundler.js:2697:29)
        at flushPostFlushCbs (runtime-core.esm-bundler.js:341:32)
        at flushJobs (runtime-core.esm-bundler.js:395:9)
    

    I tried some solutions from opened issues in here and still won't to work, i tried also to downgrade the version, and the same thing.

    Thanks.

    opened by YassineChe 0
  • [DISCUSSION] This project's future

    [DISCUSSION] This project's future

    Why this issue is here

    In the issue #152 we were talking about this project not being maintained anymore. Right now we have 4 PR, in which fixes some small bugs and adds some features, like issue #125 (PR #145).

    My motivation

    I'm following this project since the start of this year and this is the best Google Maps I've found so far. Since August, I notice that most of the open issues are not being answered anymore, so I've been following this repository since then.

    Why it should be forked by the community

    • @fawmi made a great job and I'm grateful for him creating this repo and making it better since the start. This project belongs to him and there is no one who deserves more credits than him. The community should fork it and keep it active until Fawmi decides what to do with it;

    • Accessing Fawmi's profile you will find that he is inactive since July/2022. The coincidence is that it was when he updated this repo for the last time;

    • This repo is important and has a great potential;

    Who should fork it

    IMO, anyone who have the motivation, the responsability and wants to make it better. If you want to do it, please remember that this project belongs to Fawmi and the community.

    Why I didn't forked it

    TBH I would do it right now, but I believe all the community has a voice, so I want your opinion. Also, I never had a project forked or made something in this level of importance, so I would need help to keep the project maintained.

    I will do anything I can to help if someone decides to fork it.

    edit: all my edits were made to fix the text.

    opened by NathanAP 7
Releases(0.2.0)
Owner
Fawad Mirzad
Senior web developer at @arndtteunissen GmbH. JavaScript (React, Vue.js and Node), PHP (TYPO3 and Laravel).
Fawad Mirzad
Google maps component for vue with 2-way data binding

CONTRIBUTORS NEEDED! It's been increasingly difficult for me to make time to maintain this project. My projects at work have also gradually migrated a

Daniel Sim 1.9k Jan 6, 2023
Integrate Google Maps in your Vue application

vue-googlemaps Integrate Google Maps in your Vue application in a "Vue-way". This library is Work In Progress. More components will be available in th

Guillaume Chau 534 Nov 2, 2022
A lightweight Google Maps plugin for Vue

x5-gmaps (Live Demo) This is a lightweight Google Maps plugin for Vue. Samples/examples/tutorials Tutorial creating a COVID Heatmap Address Autocomple

Keagan Chisnall 102 Oct 5, 2022
Google maps component for vue with 2-way data binding

vue-google-maps Demo: Demo in production Showcase with a lot of features Presentation If you want to write google map this way : <map :center="{lat:

Guillaume Leclerc 556 Nov 21, 2022
Using Google Maps with Vue.js

stores-map Project setup npm install Compiles and hot-reloads for development npm run serve Compiles and minifies for production npm run build Run

Edoardo Gargano 6 Apr 22, 2022
📍 Vue composable for Google Maps Places Autocomplete.

v-use-places-autocomplete ?? Vue composable for Google Maps Places Autocomplete. Though not a fork, this composable is fully inspired by react-google-

Robert Soriano 17 Dec 31, 2022
A wrapper component for consuming Google Maps API built on top of VueJs v2.

A wrapper component for consuming Google Maps API built on top of VueJs v2. Fork of the popular vue-google-maps plugin.

Diego A. Zapata Häntsch 144 Jan 5, 2023
Vue 2 components for Leaflet maps

Vue2Leaflet Vue2Leaflet is a JavaScript library for the Vue framework that wraps Leaflet making it easy to create reactive maps. How to install npm in

Vue Leaflet 1.9k Dec 29, 2022
Integrate Azure Maps in your Vue application

Vue Azure Maps Vue Azure Maps is a library for Vue.js that integrates Azure Maps. It offers several Vue components out of the box and supports custom

Ricardo Ruiz 23 May 19, 2022
Yandex Maps Component for VueJS

vue-yandex-maps Documentation: RU, EN Contributors ✨ Thanks goes to these wonderful people (emoji key): Wormaster ?? Nikitenko Andrey ?? Kamil ?? Alex

null 338 Dec 28, 2022
Annotate maps and generate GeoJSON in Kirby by drawing markers, paths and shapes

Kirby Mapnotator Annotate maps and generate GeoJSON in Kirby by drawing markers, paths and shapes. Overview This plugin is completely free and publish

Sylvain Julé 28 Nov 9, 2022
vue google map custom marker component

vue2-gmap-custom-marker This component allows you to display custom HTML content on the map using Overlay. This component is an adaptation of the Goog

eric regnier 130 Sep 14, 2022
Vue with Typescript and Google Map

CONTRIBUTORS NEEDED! My projects at work have also gradually migrated away from Google Maps (but still on Vue -- Vue's awesome!), so there's less and

An Nguyen Van 8 Oct 16, 2021
a simple component to generate an static google map

vue-static-map a simple component to generate an static google map Google Documentation Demo SandBox JSBin example Requirements Vue 2.X.X Usage Instal

Eduardo P. Rivero 23 Nov 24, 2022
Traveliko - Travel with Friends ~ Web application prepared using Google Street View API that allows you to real-time travel with your friends in the same place in street view mode.

Traveliko - Travel with Friends! You can create a room with your friends and travel in street view mode and navigate the map. The application basicall

İlker Güldalı 6 Nov 27, 2022
🔍 Google Place Autocomplete Search - Renderless component + Wrappers for Bulma, Bootstrap and more...

vue-custom-google-autocomplete Installation You need Vue.js version 2.0+ and an Google PLACE API key. This plugin is a renderless component. It comes

Damien Roche 31 Jul 11, 2022
🗺 Vue Mapbox GL - A small components library to use Mapbox GL in Vue

?? Vue Mapbox GL A small components library to use Mapbox GL in Vue. Installation & usage Have a look at the small guide for information on how to set

Studio Meta 48 Dec 18, 2022
Baidu Map components for Vue 2.x

VUE BAIDU MAP Baidu Map components for Vue 2.x Languages 中文 English Documentation https://dafrok.github.io/vue-baidu-map Get Start Installation npm i

马金花儿 2.3k Jan 5, 2023
Web map Vue components with the power of OpenLayers

VueLayers Web map Vue components with the power of OpenLayers Overview VueLayers is components library that brings the powerful OpenLayers API to the

Vladimir Vershinin 664 Dec 2, 2022