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
string
default:"''"
The primary address or street name.
string
default:"''"
Additional address details (e.g., apartment, suite).
string
default:"''"
The name of the city.
string
default:"''"
The state or region.
string
default:"''"
The postal or ZIP code.
string
default:"''"
The country name or code.
string
default:"''"
The latitude coordinate.
string
default:"''"
The longitude coordinate.
locationField model in your Vue.js component, import and initialize it as follows:
Props
object
default:"undefined"
The value bound to each input field.
number | string
default:"100"
The width of the component as a percentage.
string
default:"''"
CSS classes applied to the map container.
array | object
default:"[]"
List of states to populate the
State dropdown.object
default:"{}"
Defines the key-value structure for state options.
array | object
default:"[]"
List of countries to populate the
Country dropdown.object
default:"{}"
Defines the key-value structure for country options.
boolean
default:"false"
Toggles latitude/longitude fields and map integration.
string
default:"''"
Google Maps API key for map functionality.
array | object
default:"{zoom: 8, center: {...}}"
Google Maps configuration object (e.g., zoom level, center coordinates).
array
default:"[]"
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
event
Triggered when a key is released in an input field.
event
Triggered when a dropdown or input value changes.
event
Triggered when an input field loses focus.
event
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.