Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/olefirenko/vue-google-autocomplete
A Vue.js autosuggest component for the Google Places API.
https://github.com/olefirenko/vue-google-autocomplete
autocomplete google-places-api vue-component vuejs
Last synced: about 2 months ago
JSON representation
A Vue.js autosuggest component for the Google Places API.
- Host: GitHub
- URL: https://github.com/olefirenko/vue-google-autocomplete
- Owner: olefirenko
- License: mit
- Created: 2017-02-22T12:20:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T06:55:49.000Z (about 1 year ago)
- Last Synced: 2024-01-20T05:03:46.323Z (5 months ago)
- Topics: autocomplete, google-places-api, vue-component, vuejs
- Language: JavaScript
- Homepage: https://olefirenko.github.io/vue-google-autocomplete/
- Size: 1.23 MB
- Stars: 506
- Watchers: 9
- Forks: 262
- Open Issues: 101
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Lists
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesomer-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
- awesome-vue - vue-google-autocomplete β 350 - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
- awesome-vue. - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
- awesome-vue - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (Components & Libraries / UI Components)
- awesome-vuejs - vue-google-autocomplete - A Vue.js (2.x) autosuggest component for the Google Maps Places API. (UI Components / Form)
README
# Vue Google Autocomplete
[![npm version](https://badgen.net/npm/v/vue-google-autocomplete)](https://www.npmjs.com/package/vue-google-autocomplete) [![sponsored_by](https://badgen.net/badge/sponsored%20by/%F0%9F%A4%96Easy-Peasy.AI/f2a)](https://Easy-Peasy.AI/?utm_source=npm&utm_medium=badge&utm_campaign=vue_google_autocomplete)
A Vue.js (2.x) autosuggest component for the Google Maps Places API.
## Demo
Live demo: [olefirenko.github.io/vue-google-autocomplete](https://olefirenko.github.io/vue-google-autocomplete/)
## Benefits
I have tried to use different Vue Google Autocomplete components, but did not find any that would solve my needs. So below I would like to mention what you can get from this exact component:
- Load more than one autocompletion inputs (I could not achieve this with existing vue components)
- Getting geolocation data (latitude, longitude) for found address object along with other address data (country, city, state, county, street, house number, zip code). So no need to do additional geocode request on backend side.
- No external dependencies
- You can get access to underlying [PlaceResult object](https://developers.google.com/maps/documentation/javascript/reference#PlaceResult) to get more details about found location. You are able to specify the specific fields you want to fetch from the PlaceResult object.
- You can limit results to specific country or use users geolocation data## Installation
This component uses Google Maps Places API to get geo suggests for autocompletion, so you have to include the Google Maps Places API in the `` of your HTML:
```html
β¦
β¦
```
To obtain API key please visit the [Google Developer Console](https://console.developers.google.com). The API's that you have to enable in your Google API Manager Dashboard are [Google Maps Geocoding API](https://developers.google.com/maps/documentation/geocoding/start), [Google Places API Web Service](https://developers.google.com/places/web-service/) and [Google Maps Javascript API](https://developers.google.com/maps/documentation/javascript/).
The easiest way to use Vue Google Autocomplete is to install it from **npm** or **yarn**.
```sh
npm install vue-google-autocomplete --save
```Or
```sh
yarn add vue-google-autocomplete
```## Usage
The Vue Google Autocomplete works out of the box by just including it.
```js
import VueGoogleAutocomplete from "vue-google-autocomplete";
```In your template you can use this syntax:
```html
```
### Properties
#### id
Type: `String`
`required` ID for the input container.
#### classname
Type: `String`
Class to the input container.
#### placeholder
Type: `String`
Default: `Start typing`The input field will get this placeholder text.
#### types
Type: `String`
Default: `address`Types supported in place autocomplete requests. [More info](https://developers.google.com/places/supported_types#table3)
You may find [this example](#correct-usage-of-the-types-parameter) helpful.
#### fields
Type: `Array`
Default: `['address_components', 'adr_address', 'alt_id', 'formatted_address', 'geometry', 'icon', 'id', 'name', 'permanently_closed', 'photo', 'place_id', 'scope', 'type', 'url', 'utc_offset', 'vicinity']`Set which data fields to return in the PlaceResult from the Google Autocomplete API when the user selects a place. [Google Autocomplete API by default returns all available data fields](https://developers.google.com/maps/documentation/javascript/places-autocomplete#get_place_information) for the selected place, which may result in additional charges and thus the API users might pay for data they don't need. This package sets a sensible default for the fields value, fetching only the Basic Data fields which do not result in any additional charges. If you want to fetch other fields in addition to the default ones, make sure that the array you pass in to the `fields` prop contains the default fields listed above, and not only the additional fields you want to fetch.
Refer to [this page](https://developers.google.com/maps/billing/understanding-cost-of-use#data-skus) for more details on how certain data fields are billed.
#### country
Type: `String`|`Array`
Default: nullOption 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:```html
```
will restrict the countries to Australia and New Zealand.
#### enable-geolocation
Type: `Boolean`
Default: `false`Bias the search towards user current location.
#### geolocationOptions
Type: [`Object`](https://developer.mozilla.org/en/docs/Web/API/PositionOptions)
Default: `{}`Allow to configure Options for [`navigator.getCurrentPosition`](https://developer.mozilla.org/en/docs/Web/API/Geolocation/getCurrentPosition)
### 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](https://developers.google.com/maps/documentation/javascript/reference#PlaceResult) is available as second parameter.
- `id` a String representing the ID of the autocomplete that triggered the event.#### 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.
- `object` an object with a key _name_ representing the user's input.
#### 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
#### error
Gets triggered when an error is encountered
### Exposed component functions
These functions are accessible by setting "ref" on the component ([Refs documentation](https://vuejs.org/v2/guide/components.html#Child-Component-Refs)). 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
#### updateCoordinates([latlng](https://developers.google.com/maps/documentation/javascript/reference#LatLng))
Call to force coordinates and update the input accordingly
#### geolocate()
Call to retrieve current position from `navigator` and update the input accordingly
### Example
Please note that you need to provide what method will listen (`v-on:placechanged`) to an event when the address data is obtained.
```html
Your Address
import VueGoogleAutocomplete from "vue-google-autocomplete";
export default {
components: { VueGoogleAutocomplete },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;
},
},
};```
#### Correct usage of the types parameter
The example below shows the correct usage of the `types` parameter, when limiting the search to cities:
```vue
```
## Contributors β¨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Dmytro Olefyrenko
π»
Daryle Dale De Silva
π»
DjilanoS
π§
Juan Villegas
π»
Hugh Saffar
π»
Ahmed
π»
Ankur Kumar
π»
Artur Grigio
π»
Brian Rutledge
π»
Bryan Miller
π»
Chris Sepic
π»
Dennis van Breukelen
π»
Dmitry Mazurok
π»
Julian Renard
π»
Leonardo Arroyo
π»
Max Lyashuk
π»
MichaΕ Gibowski
π»
Mickey Schwab
π»
Romain LΓ©ger
π»
Simon Kimber
π»
syffs
π»
Yann Bertrand
π»
ciaasteczkowy
π»
crabaux
π»
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!