All Projects → gocanto → Google Autocomplete

gocanto / Google Autocomplete

Licence: mit
Google Autocomplete Vue Componet

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Google Autocomplete

Vue Mdc
Material web components for Vue.js
Stars: ✭ 1,217 (+364.5%)
Mutual labels:  google, components
Realtime object detection
Plug and Play Real-Time Object Detection App with Tensorflow and OpenCV. No Bugs No Worries. Enjoy!
Stars: ✭ 260 (-0.76%)
Mutual labels:  google
ui
🦄 Decentraland UI
Stars: ✭ 145 (-44.66%)
Mutual labels:  components
react-google-static
🌍 A React wrapper for Google Static Maps API.
Stars: ✭ 37 (-85.88%)
Mutual labels:  google
Smart-Inspector
Fluent re-take on Unity Inspector UX. Packed with QoL improvements.
Stars: ✭ 680 (+159.54%)
Mutual labels:  components
orgenic-ui
ORGENIC UI is an MIT-licensed open source project for creating strong user interfaces with high quality web components.
Stars: ✭ 53 (-79.77%)
Mutual labels:  components
unitscss
UNITS is a simple and beautiful CSS component set.
Stars: ✭ 13 (-95.04%)
Mutual labels:  components
Switzerland
🇨🇭Switzerland takes a functional approach to Web Components by applying middleware to your components. Supports Redux, attribute mutations, CSS variables, React-esque setState/state, etc… out-of-the-box, along with Shadow DOM for style encapsulation and Custom Elements for interoperability.
Stars: ✭ 261 (-0.38%)
Mutual labels:  components
Microservices Traffic Management Using Istio
Istio is an open platform that provides a uniform way to connect, manage, and secure microservices. In this code we show how we can enable your microservices with advanced traffic management, routing and tracing capabilities leveraging Istio
Stars: ✭ 257 (-1.91%)
Mutual labels:  google
Phobos
This tool written in Python3 allows you to download any movie easily thanks to Google Dorks and Google Drive!
Stars: ✭ 59 (-77.48%)
Mutual labels:  google
pancake
Making npm work for the front end and the Australian Government Design System.
Stars: ✭ 93 (-64.5%)
Mutual labels:  components
vue-cli-plugin-import-components
🔌 Automatically import components in your Vue CLI apps.
Stars: ✭ 38 (-85.5%)
Mutual labels:  components
Checkiptools
CheckIPTools 扫描谷歌IP以及实用IP转换小工具
Stars: ✭ 253 (-3.44%)
Mutual labels:  google
uce-template
A Vue 3 inspired Custom Elements toolless alternative.
Stars: ✭ 96 (-63.36%)
Mutual labels:  components
Laravel Robots Middleware
Enable or disable the indexing of your app
Stars: ✭ 259 (-1.15%)
Mutual labels:  google
muilessium
UI Framework for simple websites - landings, blogs, etc.
Stars: ✭ 16 (-93.89%)
Mutual labels:  components
anywhere-webcomponents
A UI work in progress based on custom elements (web components) for use in anywhere.
Stars: ✭ 17 (-93.51%)
Mutual labels:  components
Google-rank-tracker
SEO: Python script + shell script and cronjob to check ranks on a daily basis
Stars: ✭ 124 (-52.67%)
Mutual labels:  google
Ui Neumorphism
📕 React component library designed on the "new skeuomorphism" or "neumorphism" UI/UX trend.
Stars: ✭ 258 (-1.53%)
Mutual labels:  components
React Weui
weui for react
Stars: ✭ 2,793 (+966.03%)
Mutual labels:  components

Google Autocomplete

Demo Version Downloads Downloads License Vue1.*

I am sharing this component because I was overwhelmed by complicated examples to achieve this simple job. So, I will try to be as simple as I can during my explanation.

Google Autocomplete component is no more than a Vue.js wrapper around the official Google Places API. In spite of the demo written in Vue.js, the Autocomplete object can be pulled in from any JS framework.

Requirements

You will have to install Vue & Vuemit:

npm install vue --save
npm install vuemit --save

The Vuemit library is used to manage the events between the google component and its parent one.

Note: If you happen to be using Vue 1.*, you will have to pull from the vue-1 branch.

Demo

View live demo.

example

Installation

To install this package you just need to open your console and type npm i google-autocomplete-vue --save. If there are any problems during the installation, you can try again using the force param: npm i -f google-autocomplete-vue --save

Getting started

First of all, you have to sign up on Google API Console to get your API key: https://console.developers.google.com Once this has been done, you will have to copy the API KEY given by google and paste it in your JS file entry point. Example:

  • Bootstrap File: bootstrap.js. You will have to require Vuemit in this file to have the events handler set globaly. As so: Example

  • Entry point file: demo.js

Note: Important keys have to be kept within an .env file, so be aware of this while pushing your code to your git control.

Second of all, you will have to import the component in your application entry point, so you can call it globally when needed. Example:

import GoogleAutocomplete from 'google-autocomplete-vue';

Validation on server side

Places validation is a laravel library that will help you out to handle your user addresses. Its aim is making sure addresses submitted by users are valid through 3rd party services, as google.

Take a look at its repository: Places Validation

Guide

  • First of all, you have to create an entry point to compile the component and generate your bundle file. An example is available here.

  • Second of all, you will have to create your vue object to control the component:

require('./bootstrap');


new Vue({

    el: '#demo',


    data:
    {
        output: {}, address: {}, sent: false, response: {}, config: {}
    },


    mounted()
    {
        //Set an event listener for 'setAddress'.
        Vuemit.listen('setAddress', this.onAddressChanged);
        Vuemit.listen('addressWasCleared', this.onAddressCleared);
    },


    methods:
    {
        /**
         * Submit the data to be evaluated.
         *
         * @return {Void}
         */
        submit()
        {
            this.sent = true;
            this.output = this.address;
            this.address = {};
        },


        /**
         * Checks whether the output data is valid.
         *
         * @return {Bool}
         */
        isValid()
        {
            return Object.keys(this.output).length > 0;
        },


        /**
         * Checks whether the output data is not valid.
         *
         * @return {Bool}
         */
        isNotValid()
        {
            return ! this.isValid();
        },


        /**
         * The callback fired when the autocomplete address change event is fired.
         *
         * @param {Object}
         * @return {Void}
         */
        onAddressChanged(payload)
        {
            if (Object.keys(paypload.place).length > 0) {
                this.address = payload.address;
                this.response = payload.response;
            }
        }

        /**
         * The callback fired when the autocomplete clear event is fired.
         *
         * @param {Object}
         * @return {Void}
         */
        onAddressCleared()
        {
            this.address = {};
            this.response = {};
        }
    }
});

See the example here.

  • Third of all, you have to compile these two files with browserify, webpack or laravel-elixir-vue-2 to make them readable for every browser. Example:
require('laravel-elixir-vue-2');
var elixir = require('laravel-elixir');

elixir.config.sourcemaps = false;
elixir.config.assetsPath = 'src';

elixir(function(mix)
{
    mix.webpack('demo.js', 'dist/demo.js');
});

See the example here

  • Finally, you can use the component in your HTML file using this syntax:
<google-autocomplete
    class = "input"
    input_id = "txtAutocomplete"
    :config = "{type: ['geocode']}"
    placeholder = "type your address"
>
</google-autocomplete>

:config is the config passed to the Autocomplete constructor of the places API. See the documentation. Config corresponds to the options argument in the doc.

See the example here.

Also, you can pass any css class through the "class" prop.

Contributing

Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.

License

The MIT License (MIT). Please see License File for more information.

How can I thank you?

Why not star the github repo? Share the link for this repository on Twitter? Spread the word!

Don't forget to follow me on twitter!

Thanks!

Gustavo Ocanto. [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].