# Simple location-based search for Kirby

**URL:** <https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481>\
**Category:** Solutions\
**Tags:** v2\
**Created:** [March 16, 2015, 3:10pm UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481 "2015-03-16T15:10:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bastianallgeier](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bastianallgeier/32/7569_2.png) [@bastianallgeier](https://forum.getkirby.com/u/bastianallgeier)\
**Post date:** [March 16, 2015, 3:10pm UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/1 "2015-03-16T15:10:49Z")

</div>

I’m currently working on a radius-based retailer search for a client and thought the code for the radius search might be helpful for you as well. It shows that Kirby can handle location-based search features pretty easily. You just need to store lat (Latitude) and lng (Longitude) values in your content files and you are ready to go:

> <https://gist.github.com/bastianallgeier/6dcd06f66e23f0d4e2a5>

---

<div class="post-metadata">

**Author:** ![franzwalter](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/franzwalter/32/11968_2.png) [@franzwalter](https://forum.getkirby.com/u/franzwalter)\
**Post date:** [March 16, 2015, 9:06pm UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/2 "2015-03-16T21:06:36Z")

</div>

Hey Bastian, thanks for sharing this. A while ago I did something which might complement your post: creating dynamic markers on a map with latitude/longitude information entered through the panel.

In this case the client inserts the lat & lng values and this populates a view in which all projects are displayed on a world-map.

It’s a pretty basic implementation and could be significantly improved but given how easy it was to set it all up I thought it might be worth sharing.

[http://drehxtrem.de/where](http://drehxtrem.de/where)

---

<div class="post-metadata">

**Author:** ![lekkerduidelijk](https://avatars.discourse-cdn.com/v4/letter/l/9e8a1a/32.png) [@lekkerduidelijk](https://forum.getkirby.com/u/lekkerduidelijk)\
**Post date:** [March 22, 2015, 12:09am UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/3 "2015-03-22T00:09:55Z")

</div>

I created this geolocation custom field for Kirby panel a while back. It fetches lat/lng for any address you enter.

> **[lekkerduidelijk/kirby-geolocation-field](https://github.com/lekkerduidelijk/kirby-geolocation-field)**
>
> Geolocation panel field for Kirby 2. Contribute to lekkerduidelijk/kirby-geolocation-field development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![shiftsave](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/shiftsave/32/708_2.png) [@shiftsave](https://forum.getkirby.com/u/shiftsave)\
**Post date:** [July 22, 2015, 5:12am UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/4 "2015-07-22T05:12:18Z")

</div>

> [@lekkerduidelijk](#):
>
> [GitHub - rutger1140/kirby-geolocation-field: Geolocation panel field for Kirby 2](https://github.com/lekkerduidelijk/kirby-geolocation-field)

Hi @franzwalter would you mind sharing your implementation of this map? I am looking at implementing a similar map with search functionality (if possible)

Any guidance would be great!  
I

---

<div class="post-metadata">

**Author:** ![franzwalter](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/franzwalter/32/11968_2.png) [@franzwalter](https://forum.getkirby.com/u/franzwalter)\
**Post date:** [July 22, 2015, 9:29am UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/5 "2015-07-22T09:29:16Z")

</div>

Hi @shiftsave, below the template code I use for the custom map and populate it with the markers. The code could surely be improved but it works for now. Also caching might be a good idea if the amount of markers increases.

If you are looking into a search functionality I would let kirby generate a json-file with the geo-data. Maybe this might help you to get started: [https://www.mapbox.com/mapbox.js/example/v1.0.0/geojson-marker-from-url](https://www.mapbox.com/mapbox.js/example/v1.0.0/geojson-marker-from-url)

[https://gist.github.com/franzwalter/311b5e364c9938e8345c](https://gist.github.com/franzwalter/311b5e364c9938e8345c)

---

<div class="post-metadata">

**Author:** ![shiftsave](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/shiftsave/32/708_2.png) [@shiftsave](https://forum.getkirby.com/u/shiftsave)\
**Post date:** [July 22, 2015, 1:43pm UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/6 "2015-07-22T13:43:34Z")

</div>

Thanks @franzwalter I tried implementing it with my current structure but get the following error:

```
<b>Notice</b>: Array to string conversion in <b>/Users/ivan/Documents/Personal/Traitor Cycles/Development/public/site/templates/map.php</b> on line <b>12</b><br />
Array<br />
<b>Fatal error</b>: Call to a member function loclong() on a non-object in <b>/Users/ivan/Documents/Personal/Traitor Cycles/Development/public/site/templates/map.php</b> on line <b>14</b><br />

```

My blueprint fields looks like this:

```
locations:
label: Locations
type: structure
entry: >
  <strong>{{name}}</strong>
  {{url}}<br />
fields:
  name:
    label: Store Name
    type: text
  loclat:
    label: Latitude
    type: text
  loclong:
    label: Longitude
    type: text
  url:
    label: Website
    type: url

```

And my template file script:

```
<script>
L.mapbox.accessToken = 'pk.eyJ1Ijoic2hpZnRzYXZlIiwiYSI6IjUzYTZmMGE0YjE4Yzg3Yjk1ZTNjYThhZjZlMGMxNDJiIn0.UmZefNeJLKa8UUhHt7Vf8A';
var map = L.mapbox.map('map', 'shiftsave.84cbb874')
    .setView([41.739, 29.399], 4);
var myLayer = L.mapbox.featureLayer().addTo(map);
var geojson = {
    type: 'FeatureCollection',
    features: [
    // run through all projects and build the markers
    <?php echo $locations = $page->locations()->yaml() ?>
    <?php foreach($locations as $item): ?>
    <?php if ($item->loclong() != '' AND $item->loclat()!= ''): ?>
    {
        type: 'Feature',
        properties: {
            title: '<?php echo $item->name() ?>',
            'marker-color': '#AD0102',
            'marker-size': 'medium',
            'marker-symbol': 'cinema',
            url: '<?php echo $item->url() ?>'
        },
        geometry: {
            type: 'Point',
            coordinates: [<?php echo $item->loclong() ?>, <?php echo $item->loclat() ?>]
        }
    },
    <?php endif ?>
    <?php endforeach ?>
    ]
};

```

---

<div class="post-metadata">

**Author:** ![franzwalter](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/franzwalter/32/11968_2.png) [@franzwalter](https://forum.getkirby.com/u/franzwalter)\
**Post date:** [July 23, 2015, 5:55am UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/7 "2015-07-23T05:55:09Z")

</div>

Can you try to replace

```
<?php echo $locations = $page->locations()->yaml() ?>
<?php foreach($locations as $item): ?>

```

with

```
<?php foreach($page->locations()->toStructure() as $item): ?>

```

[http://getkirby.com/docs/cheatsheet/field-methods/toStructure](http://getkirby.com/docs/cheatsheet/field-methods/toStructure)

---

<div class="post-metadata">

**Author:** ![shiftsave](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/shiftsave/32/708_2.png) [@shiftsave](https://forum.getkirby.com/u/shiftsave)\
**Post date:** [July 23, 2015, 2:15pm UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/8 "2015-07-23T14:15:03Z")

</div>

Hi @franzwalter this worked thanks so much for your help!

---

<div class="post-metadata">

**Author:** ![timgauthier](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timgauthier/32/4739_2.png) [@timgauthier](https://forum.getkirby.com/u/timgauthier)\
**Post date:** [July 28, 2015, 3:48pm UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/9 "2015-07-28T15:48:47Z")

</div>

ugh this is so much cleaner then what i ended up doing on [www.erdbeeren-funck.de](http://www.erdbeeren-funck.de) but hey the projects done 😛

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:16pm UTC](https://forum.getkirby.com/t/simple-location-based-search-for-kirby/481/10 "2025-02-06T17:16:57Z")

</div>

Archived on February 6, 2025, 5:16pm UTC


