InputLocation.vue component is a Vue.js Composition API-based component that integrates Google Maps functionality. It is designed for capturing and interacting with location data, including countries, states, cities, and geographic coordinates.
Features
Dynamic Field Rendering
Conditionally display fields based on provided props (e.g., countries, states, coordinates).
Google Maps Integration
Includes a map view and coordinate management.
Customizable Inputs
Supports v-model binding and dynamic event handling.
Validation Support
Displays errors for each input field.
Debounced Input Events
Reduces unnecessary updates for text inputs.
Usage
Basic Example
Custom States Example
locationField model is a reactive object in Vue.js designed to represent and manage the state of location data. It includes fields for address details, geographic coordinates, and other related information.
Data Structure
ThelocationField model for the v-model consists of the following properties:
Properties
The primary address or street name.
Additional address details (e.g., apartment, suite).
The name of the city.
The state or region.
The postal or ZIP code.
The country name or code.
The latitude coordinate.
The longitude coordinate.
locationField model in your Vue.js component, import and initialize it as follows:
Props
The value bound to each input field.
The width of the component as a percentage.
CSS classes applied to the map container.
List of states to populate the
State dropdown.Defines the key-value structure for state options.
List of countries to populate the
Country dropdown.Defines the key-value structure for country options.
Toggles latitude/longitude fields and map integration.
Google Maps API key for map functionality.
Google Maps configuration object (e.g., zoom level, center coordinates).
Array of error messages for specific fields.
Sates & Countries
For the propstatesShape and countriesShape, the configuration looks like this: {value: 'abbreviation', text: 'name' }. And the data for the states or countries prop looks like this:
Events
Triggered when a key is released in an input field.
Triggered when a dropdown or input value changes.
Triggered when an input field loses focus.
Triggered when the Enter key is pressed in an input field.
Methods
loadCoordinates
Loads the geographic coordinates (latitude/longitude) into the form fields.
clearCoordinates
Clears the geographic coordinates from the form fields.
Slots
This component does not use slots.Google Maps
Create or Access a Google Cloud Project- Go to the Google Cloud Console.
- Sign in with your Google account.
- Create a new project or select an existing one.
Implementation
Themap prop should match the Google MapOptions, see the docs here Google docs for MapOptions.
Notes
- Google Maps JavaScript API integration requires an API key (
apiprop). - Fields such as
Country,State, andCoordinatesare rendered conditionally based on the provided props.