Skip to main content
The 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

The 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

The locationField 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.
To create and use the 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 prop statesShape and countriesShape, the configuration looks like this: {value: 'abbreviation', text: 'name' }. And the data for the states or countries prop looks like this:
Within the component:
If you want to keep it simple, you can use an array of values and the shape props will not be required:
Within the component:

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.
A map ID is an identifier that’s associated with a specific map style or feature. Configure a map style and associate it with a map ID in the Google Cloud Console. Then, when you reference a map ID in your code. Google documentation for using “Map IDs”

Implementation

The map prop should match the Google MapOptions, see the docs here Google docs for MapOptions.
You need coordinates on the component for Google Maps to get enabled.

Notes

  • Google Maps JavaScript API integration requires an API key (api prop).
  • Fields such as Country, State, and Coordinates are rendered conditionally based on the provided props.