Vue Google Autocomplete is a Vue.js 2.x component that provides autosuggest functionality powered by the Google Maps Places API. It aims to address common limitations found in other similar components, such as supporting multiple autocomplete inputs on a single page and directly fetching comprehensive geolocation data (latitude, longitude, address components) without requiring additional geocoding requests. The current stable version is 1.1.4, with recent updates focusing on adapting to Google API changes (e.g., deprecated data fields) and adding features like controlling fetched PlaceResult fields and disabling the input. The package does not have external JavaScript dependencies beyond Vue itself, relying solely on the Google Maps JavaScript API which must be loaded separately in the HTML head. Its primary differentiation is ease of integration for detailed address capture and efficient API usage through explicit field selection.
npm install vue-google-autocompleteVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic usage of `vue-google-autocomplete`, including how to register the component, bind properties, listen for the `placechanged` event, and display the returned address data. It highlights the `id`, `classname`, `placeholder`, `country`, `types`, and `fields` props for customization and API cost optimization, along with a simple data display.
Ensure you are on the latest patch version (1.1.4 or newer) to benefit from these fixes. If you encounter unexpected data fields or missing information, consult the Google Places API documentation and update your component.
Add `<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&libraries=places"></script>` to your `index.html` file, replacing `YOUR_API_KEY_HERE` with a valid API key from Google Cloud Console.
Utilize the `fields` prop to explicitly list only the `PlaceResult` data fields you require. Example: `:fields="['geometry', 'address_components', 'formatted_address']"`. Refer to Google Places API documentation for available fields.
Visit the Google Developer Console, navigate to your project, and ensure that 'Google Maps Geocoding API', 'Google Places API Web Service', and 'Google Maps JavaScript API' are all enabled for your project.
Ensure your Google Maps API script tag in `index.html` looks like this: `<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&libraries=places"></script>`. Double-check your API key and ensure it's correctly enabled in Google Cloud Console.
Make sure the Google Maps API script tag is placed in the `<head>` section of your `index.html` *before* your main application script. Alternatively, you might need to use a deferred loading mechanism for the Google script if it's dynamically added.
Go to the Google Cloud Console, navigate to your project, then to 'APIs & Services' -> 'Enabled APIs & services', and enable 'Google Places API Web Service'.