A beautifully simple Google Map field type for Craft CMS. Full localization support, compatible with Matrix, supports searching by location and sorting by distance.
Clone this repo into craft/plugins/simplemap
.
Create the field as you would any other.
The field type will return an array containing lat
, lng
, zoom
, address
, and parts
. This means you can use {{ myMapField.lat }}
.
parts
This contains the locations address, broken down into its constituent parts. All values are optional so you'll need to have checks on any you use to make sure they exist.
A list of the available values can be found here.
To access the short version of any part, append _short
to the end of its name. E.g. {{ myMapField.country_short }}
.
Searching and Sorting
You can search for elements using the location specified in your map field. When searching by your map field you also have the option to sort the results by distance.
{% set entries = craft.entries.myMapField({
location: 'Maidstone, Kent, UK',
radius: 100,
unit: 'mi'
}).order('distance') %}
location
: Can either be an address string (requires a Google Maps Geocoding API key) or a Lat Lng Array ({ 'lat': 51.27219908, 'lng': 0.51545620 }
orcraft.simpleMap.latLng(51.27219908, 0.51545620)
).radius
: The radius around the location to search. Defaults to50
.unit
: The unit of measurement for the search. Can be eitherkm
(kilometers) ormi
(miles). Defaults tokm
.
API Keys
You can access your browser API key in templates using craft.simpleMap.apiKey
.
- Added option to hide the map, leaving only the address input
- Added ability to restrict auto-complete by country, address type, and boundary
- Added
_short
prefix to all parts, returning the short value. You will need to re-save your entries for this to take effect. - Fixed map JS erroring when in globals
- Merged API keys into one
- The address input automatically updates the map after paste
- Browser API key can now be accessed in templates
- Added Browser API key setting
- Fixed bug where map would not display correctly when in a secondary tab.
- Added search and sorting support.
- Added optional Google API Server Key setting
- WARNING: This update will break any map fields that are NOT standalone (global) or in a Matrix field.
- Fix #5 via @jripmeester - Fixed Lat / Lng being populated with function, not number.
- Added
parts
to the fieldtype output.
- Merged #2 & #3 from @cballenar
- #2 - Field now stores map zoom
- #3 - Improved handling of unknown locations
- Improved error message display
- Added link to docs
- Added releases json for updates
- Fixed: Hidden Lat/Lng/Address fields are now cleared when the Address Search input is empty.
- Initial Release
Copyright © 2015 Ether Creative [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.