• Stars
    star
    534
  • Rank 83,095 (Top 2 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Integrate Google Maps in your Vue application

vue-googlemaps

npm npm vue2

Integrate Google Maps in your Vue application in a "Vue-way".

This library is Work In Progress. More components will be available in the 1.0 release.

Live demo

The main objective of the library is to use Google Maps using Vue components in a way that feels natural to Vue developpers (with props, events, slots...).

Become a Patreon

Sponsors

Gold

sum.cumo logo

Silver

VueSchool logo Vue Mastery logo

Bronze


Table of Contents

Installation

npm i -S vue-googlemaps
yarn add vue-googlemaps

You need to polyfill some ES2015 features in old browsers.

Usage

You need a Google API key from the developer console.

import 'vue-googlemaps/dist/vue-googlemaps.css'
import VueGoogleMaps from 'vue-googlemaps'

Vue.use(VueGoogleMaps, {
  load: {
    // Google API key
    apiKey: 'your-google-api-key',
    // Enable more Google Maps libraries here
    libraries: ['places'],
    // Use new renderer
    useBetaRenderer: false,
  },
})

Builtin components

(Documentation is work-in-progress)

  • Circle
  • Geocoder
  • Map
  • Marker
  • NearbyPlaces
  • PlaceDetails
  • UserPosition
  • More to come!

Create you own components

Here is an example of what a Marker component would look like:

import { MapElement } from 'vue-googlemaps'

// Those Vue props will update automatically
// (Two-way binding with .sync modifier)
const boundProps = [
  'animation',
  'clickable',
  'cursor',
  'draggable',
  // ...
]

// Events from Google Maps emitted as Vue events
const redirectedEvents = [
  'click',
  'rightclick',
  'dblclick',
  'drag',
  // ...
]

export default {
  mixins: [
    // You need to use this mixin
    MapElement,
  ],

  // When Google Maps is ready
  googleMapsReady () {
    const options = Object.assign({}, this.$props)
    options.map = this.$_map

    // Create Google Maps objects
    this.$_marker = new window.google.maps.Marker(options)
    // Bind the Vue props
    this.bindProps(this.$_marker, boundProps)
    // Emit the events from Google Maps
    this.redirectEvents(this.$_marker, redirectedEvents)
  },

  beforeDestroy () {
    // Teardown
    if (this.$_marker) {
      this.$_marker.setMap(null)
    }
  },
}

Quick Examples

Map with markers

<googlemaps-map
  :center.sync="center"
  :zoom.sync="zoom"
  :options="mapOptions"
  @idle="onIdle"
  @click="onMapClick">

  <!-- User Position -->
  <googlemaps-user-position
    @update:position="setUserPosition"
  />

  <googlemaps-marker
    v-for="marker of markers"
    :key="marker._id"
    :label="{
      color: marker === currentmarker ? 'white' : 'black',
      fontFamily: 'Material Icons',
      fontSize: '20px',
      text: 'star_rate',
    }"
    :position="marker.position"
    @click="selectMarker(marker._id)"
  />
</googlemaps-map>

Place Details

<googlemaps-place-details
  :request="{
    placeId: placeId
  }"
  @results="results => ..."
>
  <template slot-scope="props">
    <div class="name">{{ props.results.name }}</div>
    <div class="address">{{ props.results.formatted_address }}</div>
  </template>
</googlemaps-place-details>

Geocoder

<googlemaps-geocoder
  :request="{
    location: latLng,
  }"
  @results="results => ..."
>
  <template slot-scope="props">
    <div class="name">{{ props.results[1].name }}</div>
    <div class="address">{{ props.results[0].formatted_address }}</div>
  </template>
</googlemaps-geocoder>

Nearby places

<googlemaps-map
  @idle="map => mapBounds = map.getBounds()"
/>

<googlemaps-nearby-places
  :request="{
    bounds: mapBounds
  }"
  :filter="result => !result.types.includes('locality')"
  @results="results => ..."
>
  <template slot-scope="props">
    <div v-if="props.loading">Loading...</div>

    <div v-for="result of props.result">
      <div>
        <img
          v-if="result.photos"
          :src="result.photos[0].getUrl({ maxWidth: 80, maxHeight: 80 })"
        />
        {{ result.name }}
      </div>
      <div>{{ result.vicinity }}</div>
    </div>
  </template>
</googlemaps-nearby-places>

More Repositories

1

vue-virtual-scroller

⚡️ Blazing fast scrolling for any amount of data
Vue
8,256
star
2

floating-vue

💬 Easy tooltips, popovers, dropdown, menus... for Vue
TypeScript
2,955
star
3

vue-observe-visibility

Detect when an element is becoming visible or hidden on the page.
JavaScript
1,619
star
4

guijs

🐣️ The app that makes your #devlife easier.
Vue
1,276
star
5

peeky

A fast and fun test runner for Vite & Node 🐈️ Powered by Vite ⚡️
TypeScript
683
star
6

vue-9-perf-secrets

Demos from my talk "9 performance secrets revealed"
Vue
555
star
7

vue-mention

Mention component for Vue.js
Vue
496
star
8

vue-resize

A generic component to detect DOM elements resizing
JavaScript
491
star
9

vue-cli-plugin-apollo

🚀 @vue/cli plugin for Vue Apollo
JavaScript
477
star
10

vue-cli-plugin-ssr

✨ Simple SSR plugin for Vue CLI
JavaScript
444
star
11

vue-progress-path

Progress bars and loading indicators for Vue.js
Vue
421
star
12

awesomejs.dev

Find awesome packages for the framework you are using
Vue
205
star
13

nodepack

📦 A progressive Node.js framework
JavaScript
200
star
14

monorepo-run

Run scripts in monorepo with colors, streaming and separated panes
JavaScript
184
star
15

vue-summit-app

Example App: Vue + GraphQL + Apollo (Devfest Nantes 2017)
JavaScript
183
star
16

vue-supply

Create resources that can automatically be activated and deactivated when used (like subscriptions)
JavaScript
159
star
17

vue-share-components

vue-cli template to publish components easily
JavaScript
153
star
18

portless

Easy local domains with superpowers
TypeScript
113
star
19

vue-apollo-example

Simple vue-apollo example app
Vue
107
star
20

apollo-server-example

A very simple Apollo GraphQL server
JavaScript
92
star
21

vue-router-multi-view

router-view meet v-show meet keep-alive
JavaScript
87
star
22

vue-apollo-todos

Vue Apollo GraphQL mutation examples
Vue
80
star
23

frontpage-vue-app

Apollo "hello world" app, for Vue 2.0
Vue
79
star
24

vueconf-2017-demo

VueConf 2017 GraphQL client demo
Vue
79
star
25

vue-safe-teleport

Recommended for teleporting inside the app
TypeScript
72
star
26

graphql-migrate

🔀 Instantly create or update a SQL database from a GraphQL API schema
TypeScript
58
star
27

kickstart-meteor-vue-huge-app

Example meteor project featuring vue, code-splitting and hot-reload
Vue
48
star
28

meteor-vue2-example

Meteor & Vue 2.0 example
Vue
44
star
29

packt-vue-project-guide

Vue Project Guide Book Sources
JavaScript
42
star
30

reactive-fs

Reactive file system interface
TypeScript
38
star
31

sheep

🐑 Opinionated CLI command to release pnpm monorepos
TypeScript
38
star
32

vue-typegen

Generate types for TypeScript Vue components libraries
TypeScript
37
star
33

blaze2

Vue-powered blaze
JavaScript
35
star
34

meteor-vite

JavaScript
34
star
35

meteor-vue-example

Simple meteor example with vue
Vue
31
star
36

vue-perf-tests

Demos for my 'Vue performance tricks' talk
Vue
27
star
37

meteor-socket-io

Simple meteor example with socket.io
JavaScript
25
star
38

window-button-layout

Retrieve OS window buttons layout (close, maximize, minimize...)
TypeScript
21
star
39

vue-amsterdam-2018

🚀 Demo sources of my talk at Vue Amsterdam 2018
18
star
40

graphql-annotations

Annotate a GraphQL schema
JavaScript
17
star
41

mincopy

a CLI that synchronizes two folders with minimal writes
JavaScript
14
star
42

vue3-devtools-plugin-example

JavaScript
14
star
43

meteor-vue2-example-routing

Simple meteor example with vue 2.x and routing
Vue
14
star
44

apollo-client-browser

A browser-ready version of apollo-client
HTML
12
star
45

nux

Node-webkit web browser
HTML
10
star
46

meteor-vuex-example

Simple meteor app with vuex
JavaScript
10
star
47

vue-ssr-after-2-6

Vue
10
star
48

vue-cli-locale-fr

French localization for @vue/cli
9
star
49

vue2-devtools-plugin-example

TypeScript
8
star
50

code-civil

Static website for the french "code civil"
JavaScript
8
star
51

vue-cli-plugin-demo

A demo plugin for Vue CLI 3
JavaScript
7
star
52

nuxt3-demo

Vue
6
star
53

vue-template-explorer

Explore Vue templates
Vue
6
star
54

meteor-vue-blaze

Example meteor project
JavaScript
5
star
55

wear-calculator

Calculator for Wear OS 3
Kotlin
5
star
56

turbo-vs-vite

Pre-generated apps from vercel/turbo bundler benchmark + additional variations
JavaScript
4
star
57

test-video-perf

Vue
4
star
58

vue-apollo-githunt

Githunt example
JavaScript
4
star
59

electron-vite-vue-test

TypeScript
4
star
60

yarn-check-node

[Yarn berry] Check node version from engines field in package.json
JavaScript
4
star
61

peeky-vue-demo

TypeScript
3
star
62

vue-example

Vue
3
star
63

nuxt-i18n-hmr

Hot reload issue reproduction for nuxt-i18n
Vue
3
star
64

guijs-generator-nuxt

Nuxt project generator for guijs
TypeScript
2
star
65

vue-test-functional

Testing functional components
Vue
2
star
66

vue-cli-plugin-fs-router

2
star
67

meteor-mysql

This is a MeteorJS package which brings strong and easy way in order to write apps using Mysql.
TypeScript
2
star
68

no-unnecessary-boolean-literal-compare-repro

2
star
69

storybook-issue-app-use

Vue
2
star
70

polytech-pokedex-2019

JavaScript
2
star
71

guijs-website

guijs website
Vue
2
star
72

mahjong

C++
1
star
73

vue-ssr-before-2-6

JavaScript
1
star
74

nuxt-fallback-404

Vue
1
star
75

unplugin-icons-issue-94

JavaScript
1
star
76

graphql-autoquery

Mysterious space augment for resolvers
1
star
77

graphql-demo

Meetup demo
JavaScript
1
star
78

webpack-issue-11612

JavaScript
1
star
79

guijs-generator-vue-cli

guijs generator for Vue CLI project
TypeScript
1
star
80

dd-apm-test-ui

Vue
1
star
81

polytech-pokedex

Vue
1
star
82

meteor-vue-example-routing

Simple meteor example with vue and routing
Vue
1
star
83

md-icons-svg

Material Icons (SVG files)
1
star
84

repro-rollup-vue2-jsx

JavaScript
1
star