vue-google-maps
This is the Vue 2.x port of vue-google-maps!
If you have used vue-google-maps with Vue 1.x before, refer to Upgrading.
Author
xkjyeah
Installation
With npm (Recommended)
npm install vue2-google-maps
In your project:
import Vue from 'vue'
import * as VueGoogleMaps from 'vue2-google-maps'
Vue.use(VueGoogleMaps, {
load: {
key: 'AIzaSyBvWE_sIwKbWkiuJQOf8gSk9qzpO96fhfY',
libraries: 'places', // This is required if you use the Autocomplete plugin
// OR: libraries: 'places,drawing'
// OR: libraries: 'places,drawing,visualization'
// (as you require)
}
})
Nuxt.js projects
For Nuxt.js projects, please import VueGoogleMaps in the following manner:
import * as VueGoogleMaps from '~/node_modules/vue2-google-maps/src/main'
This is required for successful server-side rendering.
(Note: as of v0.8.1, you should add src/main
to the path)
Manually
Just download dist/vue-google-maps.js
file and include it from your HTML.
If you use this method, Vue 2.1.x is required.
Brief
If you want to write google map this way :
<gmap-map
:center="{lat:10, lng:10}"
:zoom="7"
map-type-id="terrain"
style="width: 500px; height: 300px"
></gmap-map>
Or use the power of Vue.js within a google map like this:
<template>
<gmap-map
:center="center"
:zoom="7"
style="width: 500px; height: 300px"
>
<gmap-marker
:key="index"
v-for="(m, index) in markers"
:position="m.position"
:clickable="true"
:draggable="true"
@click="center=m.position"
></gmap-marker>
</gmap-map>
</template>
<script>
/////////////////////////////////////////
// New in 0.4.0
import * as VueGoogleMaps from 'vue2-google-maps';
import Vue from 'vue';
Vue.use(VueGoogleMaps, {
load: {
key: 'YOUR_API_TOKEN',
v: 'OPTIONAL VERSION NUMBER',
// libraries: 'places', //// If you need to use place input
}
});
export default {
data () {
return {
center: {lat: 10.0, lng: 10.0},
markers: [{
position: {lat: 10.0, lng: 10.0}
}, {
position: {lat: 11.0, lng: 11.0}
}]
}
}
}
</script>