Hello
I’m trying to use the kirby-locator Plugin in a Structure field. I want to retrieve the Longitude/Latitude from multiple location so I can build a Map with location markers.
I tried something like this:
<?php
$items = $page->locations()->toStructure();
foreach ($items as $item): ?>
<?= $item->coordinates()->lat() ?>
<?php endforeach ?>
But now I get a «ErrorException: Array to string conversion».
It’s probably easy to resolve but Im just not so good in PHP yet
Thanks for helping
texnixe
November 13, 2019, 6:07pm
2
You have to convert $item->coordinates() to yaml:
# Kirby Locator
A simple map & geolocation field, built on top of open-source services and Mapbox.

<br/>
## Overview
> This plugin is completely free and published under the MIT license. However, if you are using it in a commercial project and want to help me keep up with maintenance, please consider [making a donation of your choice](https://www.paypal.me/sylvainjule) or purchasing your license(s) through [my affiliate link](https://a.paddle.com/v2/click/1129/36369?link=1170).
- [1. Installation](#1-installation)
- [2. Setup](#2-setup)
- [3. Tile-servers](#3-tile-servers)
* [3.1. Open-source / free tiles](#31-open-source-free-tiles)
* [3.2. Mapbox tiles](#32-mapbox-tiles)
- [4. Geocoding service](#4-geocoding-service)
* [4.1. Open-source API (Nominatim)](#41-open-source-nominatim)
* [4.2. Mapbox API](#42-mapbox-api)
This file has been truncated. show original
Thanks for your help. I’m still a bit lost
I tried this now:
<?php foreach ($page->locations()->yaml() as $location): ?>
<?= $location['lat'] ?>
<?php endforeach ?>
and I get an «Undefined index: lat»
this is the dump of $location:
Array
(
[coordinates] => Array
(
[lat] => 47.054267
[lon] => 8.289384
[number] => 12
[city] => Luzern
[country] => Switzerland
[postcode] => 6003
[address] => Bernstrasse
)
)
Array
(
[coordinates] => Array
(
[lat] => 47.054267
[lon] => 8.289384
[number] => 12
[city] => Luzern
[country] => Switzerland
[postcode] => 6003
[address] => Bernstrasse
)
)
Array
(
[coordinates] => Array
(
[lat] => 47.044094
[lon] => 8.304822
[number] => 7
[city] => Luzern
[country] => Switzerland
[postcode] => 6003
[address] => Bundesstrasse
)
)
Array
(
[coordinates] => Array
(
[lat] => 47.044094
[lon] => 8.304822
[number] => 7
[city] => Luzern
[country] => Switzerland
[postcode] => 6003
[address] => Bundesstrasse
)
)
texnixe
November 13, 2019, 9:12pm
4
No, each of your structure items has a coordinates field, so you don’t use yaml()
on the locations field (which is your structure field), but on the coordinates field inside the item, as I wrote above:
<?php
$items = $page->locations()->toStructure();
foreach ($items as $item): ?>
<?php $coordinates = $item->coordinates()->yaml(); ?>
<?php echo $coordinates['lat']; ?>
<?php echo $coordinates['lon']; ?>
<?php endforeach ?>
ahh I see thank you so much