Location Field Type
Description:
The location
field type allows users to capture geographical locations by combining an interactive map with an address input field. This field type integrates with mapping services to provide a visual representation of the location, enabling users to select a point on the map or enter an address to pinpoint the location accurately.
YAML Definition
- name: event_location
type: location
display_name: "Event Location"
guidance: "Select the location on the map or enter the address."
required: true
default_value:
latitude: 40.7128
longitude: -74.0060
Attributes
-
name (string): Required.
The unique identifier for the field. -
type (string): Required.
Must be set tolocation
for location fields. -
display_name (string): Optional.
The label displayed in the user interface. If not provided, a formatted version ofname
is used. -
guidance (string): Optional.
Help text or instructions for the field to assist users in providing the correct information. -
required (boolean): Optional.
Iftrue
, the field must be completed before submission. -
default_value (object): Optional.
A default location to display on the map when the form loads. Should includelatitude
andlongitude
properties. -
readonly (boolean): Optional.
Iftrue
, the field is read-only, and users cannot modify the location. -
hidden (boolean): Optional.
Iftrue
, the field is hidden from the user interface.
Example
- name: warehouse_location
type: location
display_name: "Warehouse Location"
guidance: "Please mark the warehouse location on the map or enter its address."
required: true
default_value:
latitude: 51.5074
longitude: -0.1278
In this example:
-
warehouse_location: Captures the geographical location of a warehouse.
-
default_value: Sets the default map position to coordinates corresponding to London.
Usage Notes
-
User Interaction:
-
Users can interact with the map to select a location by clicking on the desired point.
-
An address input field allows users to type in an address, which updates the map accordingly.
-
The map and address field are synchronized, so changes in one reflect in the other.
-
-
Capturing Location Data:
-
The field stores both the geographical coordinates (
latitude
andlongitude
) and the address details. -
This data can be used for mapping, routing, or spatial analysis within your application.
-
-
Default Values:
-
Use
default_value
to set an initial position for the map, enhancing user experience by focusing on a relevant area. -
The
default_value
should be an object withlatitude
andlongitude
properties.
-
-
Validation:
-
If
required
istrue
, ensure that the user selects a location before submitting the form. -
Implement validation to check that valid coordinates are captured.
-
-
Readonly Fields:
-
Setting
readonly
totrue
displays the location but prevents users from modifying it. -
Useful for displaying predefined locations or when the location is determined by the system.
-
-
Guidance and Labels:
-
Provide clear instructions using
guidance
to help users understand how to use the map and address input. -
Use
display_name
to give the field a meaningful label.
-
-
Use Cases:
-
Event Planning: Selecting the venue location for an event.
-
Asset Tracking: Recording the location of physical assets.
-
Service Delivery: Capturing customer locations for deliveries or on-site services.
-
-
Integration with Mapping Services:
-
The field integrates with mapping services (e.g., Google Maps) to provide geocoding and map display.
-
Ensure that any required API keys or configurations are set up in your application.
-
-
Accessibility:
-
Provide alternatives for users who may not be able to interact with the map, such as the address input field.
-
Ensure the map component is accessible via keyboard navigation and screen readers where possible.
-
-
Internationalization:
-
The map and address input should support international addresses and character sets.
-
Be mindful of regional differences in address formats.
-
By incorporating the location
field type into your schema, you enable users to specify precise geographical locations, enhancing the spatial capabilities of your application and improving data accuracy for location-dependent features.