Google Map Autocomplete in Vue.js

Today, we will learn about how we can implement Google Map Autocomplete in Vue.js


  • Basic Knowledge of Vue.js
  • Node.js tobe installed
  • API Key For Google Maps
  • Vue CLI tobe installed

Lets start.

Goto your desired path, and create a new Vue.js project

Open command prompt and type the following command to create a new project

vue create google-maps-autocomplete-vuejs

Once your project is created navigate to the project and open it in your favorite code editor.

Now, we need to install the vue js google maps package, so type the following command in the terminal to install the package.

npm i vue2-google-maps

Now open the main.js file src folder and replace the file with the below code.

import Vue from 'vue'
import App from './App.vue'
import * as VueGoogleMaps from "vue2-google-maps";

Vue.config.productionTip = false

Vue.use(VueGoogleMaps, {
  load: {
    key: "api-key",
    libraries: "places",

new Vue({
  render: h => h(App),

replace the “api-key” with your google maps key.

Now open the App.vue component file add the following code in it.

  <div id="app">
    <h2>Autocomplete Google Maps</h2>
    <GmapAutocomplete @place_changed="setPlace" />
    <button class="btn" @click="addMarker">Add</button>

      style="width: 100%; height: 400px; margin-top: 20px"
        v-for="(m, index) in markers"
        @click="center = m.position"

export default {
  name: "App",
  data() {
    return {
      center: { lat: 45.508, lng: -73.587 },
      currentPlace: null,
      markers: [],
  methods: {
    setPlace(place) {
      this.currentPlace = place;
    addMarker() {
      if (this.currentPlace) {
        const marker = {
          lng: this.currentPlace.geometry.location.lng(),
        this.markers.push({ position: marker }); = marker;
        this.currentPlace = null;

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;

.pac-target-input {
  padding: 10px;
  width: 20%;

.btn {
  margin-left: 20px;
  padding: 10px 20px;
  background-color: greenyellow;

That’s it.


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories