Please note that this documentation is for the most recent version of this extension. It may not be relevant for older versions. Related documentation can be found in the documentation directory of the extension.
Insert a location button
A location button lets visitors determine their current location via the browser. The resulting geo coordinates arethen used directly for the radius search.
Requirements
- The
Locationfilter field must be enabled in the search plugin, so that the fieldsaddress-location-field,address-latitude-fieldandaddress-longitude-fieldare available in the form. - The JavaScript
AddressManagerGetGeoLocation.jsis included automatically by the extension's TypoScript setup. - Browsers only provide the Geolocation API in a secure context (HTTPS).
- The visitor must allow access to their location in the browser.
Insert the button
The button is identified by the ID get-location-button. Add it, for example, in your own template or partial(e.g. in a copy of Partials/Address/FilterFields/Location.html):
<button type="button" id="get-location-button" data-location-text="My location">
Use my location
</button>
The data-location-text attribute defines the text shown in the location field after the location has beendetermined successfully. Use type="button" so that the button does not submit the form by itself.
Attention:
The ID
get-location-buttonmust only be used once per page.
Behavior
After a click (on touch devices on the touchend event) the visitor's location is requested. On success, latitude andlongitude are written into the hidden form fields and the search is executed:
- List/map with search form: The search is updated via AJAX, just like when submitting the search form.Pagination is reset to the first page and any pending geocoding of a free-text input is discarded. There is noredirect to the JSON endpoint.
- Search plugin with display type "Filter only" (
FilterOnly): The formaddress-search-form-redirectissubmitted regularly and the visitor is redirected to the configured list page (settings.list.defaultPid).
If the browser does not support geolocation, the button is hidden automatically. If the visitor denies the request orno location can be determined, an error message is shown as a browser alert.
Notice:
When using the radius search, results are always sorted by distance!
