A Vuetify ready Vue.js autosuggest component for the Google Places API.

Overview

Vuetify Google Autocomplete

A Vuetify ready Vue.js (2.x) autosuggest component for the Google Maps Places API.

Versions

Latest Stable: 2.0.2

See releases for details.

Thanks

Huge thanks and credit goes to @olefirenko and contributors for creating Vue Google Autocomplete from which this Vuetify ready version was inspired.

Demo

Live Interactive demo: madimetjashika.github.io/vuetify-google-autocomplete

Installation

The easiest way to use Vuetify Google Autocomplete is to install it from npm or yarn.

npm i vuetify-google-autocomplete

Or

yarn add vuetify-google-autocomplete

For version >= 2.0.0

Within your main.js or Vue entry point, import and initialise the component.

import Vue from 'vue';
import VuetifyGoogleAutocomplete from 'vuetify-google-autocomplete';

Vue.use(VuetifyGoogleAutocomplete, {
  apiKey: '...', // Can also be an object. E.g, for Google Maps Premium API, pass `{ client: <YOUR-CLIENT-ID> }`
  version: '...', // Optional
});

To obtain API key please visit the Google Developer Console. The API's that you have to enable in your Google API Manager Dashboard are Google Maps Geocoding API, Google Places API Web Service and Google Maps Javascript API.

Usage

For version >= 2.0.0

Simply start using the component in your HTML.

<vuetify-google-autocomplete
    id="map"
    append-icon="search"
    disabled="true"
    placeholder="Start typing"
    v-on:placechanged="getAddressData"
>
</vuetify-google-autocomplete>

In your template you can use this syntax:

<vuetify-google-autocomplete
    id="map"
    append-icon="search"
    disabled="true"
    classname="form-control"
    placeholder="Start typing"
    v-on:placechanged="getAddressData"
>
</vuetify-google-autocomplete>

Properties

NB: This componenent implements the same props as those specified for Vuetify Text Fields as at v1.0.3, some of which are listed below. Please see Vuetify Text Fields for a complete list of available props.

id

Type: String

required ID for the input container.

append-icon

Type: String Default: null

The icon to append to the end of the input field.

prepend-icon

Type: String Default: null

The icon to prepend at the beginning of the input field.

classname

Type: String

Class to the input container.

placeholder

Type: String Default: Search Address

The input field will get this placeholder text. Note that the input field will also get a label with the same text.

disabled

Type: Boolean Default: false

Sets the input as either disabled or not.

types

Type: String Default: address

Types supported in place autocomplete requests. More info

country

Type: String|Array Default: null

Option to restrict the autocomplete search to a particular country. Countries must be passed as a two-character, ISO 3166-1 Alpha-2 compatible country code (i.e. "br", "sg", "fr"). You can provide a single one, or an array of up to 5 country code strings. Note: this is a dynamic property. You must pass it as :country="" to your component, otherwise it won't work. For example:

<vuetify-google-autocomplete :country="['au', 'nz']"></vuetify-google-autocomplete>

will restrict the countries to Australia and New Zealand.

enable-geolocation

Type: Boolean Default: false

Bias the search towards user current location.

Events

The component emits next events, which you can listen in your application:

placechanged

Gets triggered when the address data got obtained. This data is available on the returned objects:

  • street_number, route, locality, administrative_area_level_1, country, postal_code, latitude, longitude.
  • place - PlaceResult object is available as second parameter.

no-results-found

Gets triggered when a user entered the name of a Place that was not suggested and pressed the Enter key, or the Place Details request failed.

focus

Gets triggered when the autocomplete input field receives focus.

blur

Gets triggered when the autocomplete input field loses focus.

inputChange

Gets triggered every time autocomplete input got changed

change

Gets triggered when the autocomplete results got changed

keypress

Gets triggered when a key gets pressed

Exposed component functions

These functions are accessible by setting "ref" on the component (Refs documentation). See example below how to use these functions.

clear()

Call to clear the value of the user input.

focus()

Call focus to focus on the element

blur()

Call blur to blur (unfocus) the element

update(value)

Call to update the user input with a new value

Example

Please note that you need to provide what method will listen (v-on:placechanged) to an event when the address data is obtained.

<template>
    <div>
        <h2>Your Address</h2>
        <vuetify-google-autocomplete
            ref="address"
            id="map"
            classname="form-control"
            placeholder="Please type your address"
            v-on:placechanged="getAddressData"
            country="sg"
        >
        </vuetify-google-autocomplete>
    </div>
</template>

<script>
    export default {
        data: function () {
            return {
              address: ''
            }
        },
        mounted() {
            // To demonstrate functionality of exposed component functions
            // Here we make focus on the user input
            this.$refs.address.focus();
        },
        methods: {
            /**
            * When the location found
            * @param {Object} addressData Data of the found location
            * @param {Object} placeResultData PlaceResult object
            * @param {String} id Input container ID
            */
            getAddressData: function (addressData, placeResultData, id) {
                this.address = addressData;
            }
        }
    }
</script>

Contributing

Lets make this an awesome vuetify component! Collaborations and contributions are welcome!

Contribution Guidlines

Have a read through the Contributor Code of Conduct. Pretty standard, nothing hectic.

Fork, then clone the repo:

git clone [email protected]:your-username/vuetify-google-autocomplete.git

Install dependencies with npm

npm install 

or yarn

yarn

Make your changes and ensure tests are written for your changes. Ensure that your changes pass all the tests:

npm run test

If relevant, please ensure that you update the README and demo/example accordingly.

Push to your fork and submit a pull request.

If all is well, your changes will be merged timeously!

Feel free to also post issues for bug fixes or enhancements or anything.

You might also like...
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

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

Render every single road in any city, The data is fetched from OpenStreetMap using overpass API.
Render every single road in any city, The data is fetched from OpenStreetMap using overpass API.

Render every single road in any city, The data is fetched from OpenStreetMap using overpass API.

A Vue.js component for Mapbox GL JS

Mapbox GL JS Vue.js A simple lightweight (9kb/3kb gzipped) Mapbox GL JS Vue component. Demo Installation Setup Props Events Plugins Popups Development

Choropleth Map component for Vue.js

vue-choropleth Vue components to display a choropleth map given a certain GeoJSON and another datasource to show information from. Using Vue2Leaflet H

A Vue JS component for displaying dynamic data on a world map.

This is no longer being maintained, please do not open issues or PRs. Vue World Map A Vue JS Component for displaying dynamic data on a world map. Map

Yandex Maps Component for VueJS
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

This component allows you to display custom HTML content on the map using Overlay
This component allows you to display custom HTML content on the map using Overlay

vue3-gmap-custom-marker This component allows you to display custom HTML content on the map using Overlay. This component is an update (a fork) from e

vue2 component for tf-leaflet-editable-polyline

vue2 component for tf-leaflet-editable-polyline

Owner
Geoff Baum
I am an experienced javascript engineer who loves learning about new things. I am currently the Lead Front End Architect for @GreywallSoftware
Geoff Baum
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 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
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
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
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
🔍 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
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
A set of composable components for easy use of Google Maps in your Vue 3 projects.

A set of composable components for easy use of Google Maps in your Vue 3 projects.

Inocan Group 111 Dec 29, 2022
Reactive Vue 3 components for Google maps

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

Fawad Mirzad 117 Dec 28, 2022