dolphiq / craft3-locationpicker
Craft Location picker
Installs: 562
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 4
Forks: 2
Open Issues: 0
Language:JavaScript
Type:craft-plugin
Requires
- craftcms/cms: ^3.0.0-alpha.1
- romi45/yii2-json-validator: ^1.1
This package is not auto-updated.
Last update: 2024-12-12 12:27:08 UTC
README
A location field that lets you pick a location and shows it on google maps. You also have the possibility to group multiple chosen locations.
Note: This plugin may become a paid add-on when the Craft Plugin store becomes available.
Requirements
- Craft 3.0 (beta 28)+
- PHP 7.0+
- Google Maps API Key
Installation
-
Install with Composer
composer require dolphiq/craft3-locationpicker
-
Install plugin in the Craft Control Panel under Settings > Plugins
-
The Location Field type will be available when adding a new field - Settings > Fields > Add new field
Creating a field with the location field type
- Choose the
Location Field
type - Save the field
Using the location field type
- Add the field to a field layout (for example to a section)
- You can now choose an location when creating or updating a section by clicking on the
Pick location
button - When clicking this button you will get a popup. Type the adress to search for a location.
- You will now get a dropdown list. Click on one of the options in the dropdownlist to choose a location.
- The location will be shown on the map below
- Click on the red
Select
button in the bottom right corner of the popup to use the choosen location in the entry. - If you click cancel or dismiss the popup the choosen location will not be set in the entry.
Usage sample to display a map with one location
Display a google map with the choosen location in a twig template
{{ entry.fieldName.getMap() }}
Properties of the icon field
-
Get the location address (string)
{{ entry.fieldName.address }}
-
Get the location latitude
{{ entry.fieldName.lat }}
-
Get the location longitude
{{ entry.fieldName.long }}
-
Display a map with the location. Options is an array, see options part
{{ entry.fieldName.getMap()|raw }}
Usage sample to display a map with more locations
To display more locations on the same map (a marker for every location), we use the twig function dolphiqMap
.
Lets say we have a structure called hospitals
with entries that each have a location field.
To display a map with all locations do the following in a twig template:
{% set hospitals = craft.entries.section('hospitals').all() %} {% set locations = {} %} {% for hospital in hospitals %} {% set locations = locations|merge({(loop.index) : hospital.location}) %} {% endfor %} {{ dolphiqMap(locations, {width:'100%', height:'500px'})|raw }}
Properties and options
Properties of the dolphiqMap(locations, options)
function
Properties
Map Options
Contributors & Developers
Lucas Weijers - Original developer
Brought to you by Dolphiq: info@dolphiq.nl