# Plugin: Styled Google Map – Tag and Page Methods

**URL:** <https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045>\
**Category:** Plugins\
**Created:** [March 23, 2017, 10:57am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045 "2017-03-23T10:57:05Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [March 23, 2017, 10:57am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/1 "2017-03-23T10:57:05Z")

</div>

Kirby CMS Tag and Page Method to print a regular or styled google map.

**NOTE:** This is not a free plugin. In order to use it on a production server, you need to buy a license.

## Key Features

- add your styling JSON
- turn on/off google controls
- simple customization using `config` and `snippets`
- add more than one marker
- marker can have custom marker icon image
- marker can have info window (open on click or allready opened)
- marker can open URL on click
- example code shows how to create custom text labels with svg using a route
- works out-of-the box with @AugustMiller [Kirby Map Field Plugin](https://github.com/AugustMiller/kirby-map-field).

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/1/127d1c158387894e6375d0dbf00d19cc1d12904d.gif)

[https://github.com/bnomei/kirby-styledmap](https://github.com/bnomei/kirby-styledmap)

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [March 24, 2017, 9:30am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/2 "2017-03-24T09:30:56Z")

</div>

hi @steenweg, i moved your question here.

> [@Location / Map Field](https://forum.getkirby.com/t/location-map-field/1069/12):
>
> Hi bnomei, really appreciate your plugin, will immediately use it in an actual project. BUT – I´m no “PHP crack”, therefore “real” PHP code examples instead of the “pseudo-code” for the use of the styledmap plugin on your Github page would be very helpful. Many thanks in advance Thomas

what step exactly are you stuck at?

**kirby tag**  
once you have installed the plugin you can use the `styledmap` [kirby tag](https://getkirby.com/docs/cheatsheet#kirbytags) inside the panel (inside any content textarea) so no php required at all. if [you want styling](https://github.com/bnomei/kirby-styledmap#styled-map) you can either upload a json file to the content folder or create a snippet. the snippet does not contain any real php mostly just the json – see [example provided](https://github.com/bnomei/kirby-styledmap/blob/master/snippets/sm-example-json.php).

**config**  
of course you still have to get an google map api key and add it to your `/site/config/config.php`.

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [March 24, 2017, 9:52am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/3 "2017-03-24T09:52:36Z")

</div>

Hi @bnomei,

thank you very much for your kind response! I didn´t want to sound rude, the error is on my side: I completely oversaw, that your plugin gives me a tag, that I can use in panel text fields. Now I see, how to use your examples that I erroneously described as “pseudo-code”.

Now its up to me, to use it the right way: I have an overview page/template “projects” with many children “project”. I would like to show a map on the overwiew page with markers for all children. I think, I have to build a snippet, looping through all children and collecting lat, lng, title and a link. Building this multi-dimensional associative array will be the real challenge for me.

Thanks again

Thomas

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [March 24, 2017, 10:08am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/4 "2017-03-24T10:08:50Z")

</div>

- you need to replace title with something like `$page->title()->value()` or another field
- you can omit/delete the `icon` and `info` if you do not need them

try something like this.

```
$markers = array();
foreach($projects as $project) {
    // custom
    $markers[] = 
        [	'title' => 'Makaiwa Beach Park', // $project->title()->value()
            'lat' => 21.347355, 
            'lng' => -158.127777, 
            // get an icon from somewhere. could be a svg too.
            'icon'	=> site()->url() . '/assets/plugins/kirby-styledmap/sm-example-icon.svg',
            // open url on click
            'info'	=> 'https://www.google.de/maps/place/Makaha+Beach+Park/@21.3569219,-158.1442995,12z',
        ];

    // or with kirby tag field (named in my case 'location')
    $projectmarker = 
        [	'title' => 'Makaiwa Beach Park', 
            // get an icon from somewhere. could be a svg too.
            'icon'	=> site()->url() . '/assets/plugins/kirby-styledmap/sm-example-icon.svg',
            // open url on click
            'info'	=> 'https://www.google.de/maps/place/Makaha+Beach+Park/@21.3569219,-158.1442995,12z',
        ];
    $markers[] = array_merge($projectmarker, $project->location()->yaml()); // https://github.com/AugustMiller/kirby-map-field#usage
}
echo a::json($markers);
```

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [March 24, 2017, 10:16am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/5 "2017-03-24T10:16:16Z")

</div>

Hi @bnomei,

this looks very promising, thank you so much! I will try it, as soon as possible - for the next hours I´m traveling by train with very spotty internet access.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [March 24, 2017, 10:18am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/6 "2017-03-24T10:18:41Z")

</div>

once you added the google api key to your config you could give the [example route](https://github.com/bnomei/kirby-styledmap#examples-routepage) a try to check if everything is working.

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [March 24, 2017, 10:21am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/7 "2017-03-24T10:21:46Z")

</div>

The example route works already, no problems so far. I had the Google api key already installed for the Kirby Map Field Plugin.

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [March 24, 2017, 3:01pm UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/8 "2017-03-24T15:01:26Z")

</div>

Hi Bruno,

just bought the license, will definitively use your plugin. This code works as a charm

```
<?php
$markers = array();
foreach(kirby()->site()->pages()->find('projekte')->children()->visible() as $projekt) {
  $projektmarker = [	'title' => 'Some Title',
                      'info' => 'Some Info',
                    ];
  $markers[] = array_merge($projektmarker, $projekt->location()->yaml());
}
echo a::json($markers);
?>

```

But, as soon as I try to read some information from “$projekt” into ‘title’ or ‘info’

`'title' => $projekt->title()`

I get this nasty error

Undefined property: Page::$title

Don´t understand this…

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [March 24, 2017, 3:16pm UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/9 "2017-03-24T15:16:21Z")

</div>

your blueprint needs to have the `title` field. did you create a [custom blueprint](https://getkirby.com/docs/panel/blueprints) for children of `projekte`? if you did check spelling `title` not `titel`.

you could also try to just use the value

```
$projektmarker = [	
  'title' => $projekt->title()->value(),
  'info' => 'Some Info',
];
```

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [March 24, 2017, 3:22pm UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/10 "2017-03-24T15:22:21Z")

</div>

Hi,

that solved it! My blueprint contains the “Title” field, it was the missing “-\>value()” statement.

Thanks a lot, have a nice weekend

Thomas

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [March 24, 2017, 3:33pm UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/11 "2017-03-24T15:33:47Z")

</div>

ah yes. the field object can not be converted into a string when calling `a::json` – thats why `$field->value()` is needed. you could also wrap it into a `trim($field)` etc. to trigger string conversion.

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [March 27, 2017, 11:30am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/12 "2017-03-27T11:30:33Z")

</div>

Sorry, wrong post…

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [March 27, 2017, 12:43pm UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/13 "2017-03-27T12:43:51Z")

</div>

still got the automated email. 😁  
[fixed and released version 0.5.2](https://github.com/bnomei/kirby-styledmap/releases/tag/v0.5.2)

---

<div class="post-metadata">

**Author:** ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)\
**Post date:** [April 12, 2017, 8:49am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/14 "2017-04-12T08:49:17Z")

</div>

Hi bnomei,

me, again ☹

I finished the beta of the site I´m working on. Runs without problems locally on my Mac with MAMP.

On the test server, I get a nasty error from your plugin: „unexpected end of file“

This is the URL

[http://stiftung.st.eenweg.de/aktuell/projektfoerderung-schwarzwilduebungsgatter-fuer-jagdgebrauchshunde-bei-aufsess](http://stiftung.st.eenweg.de/aktuell/projektfoerderung-schwarzwilduebungsgatter-fuer-jagdgebrauchshunde-bei-aufsess)

Attached 2 screenshots, one from the local site, one from the test server.

Would be great, if you could have a look into this

Many thanks

Thomas

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/7/74d70d94891c369db47cf3184bcac0edc9276d4e.png)

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/7/7cac960d7114550c7492ee18799afb8359bcb584.png)

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [April 12, 2017, 9:03am UTC](https://forum.getkirby.com/t/plugin-styled-google-map-tag-and-page-methods/7045/15 "2017-04-12T09:03:14Z")

</div>

yes. [texnix found that already. another php short-tag on line 91](https://github.com/bnomei/kirby-styledmap/issues/2).  
fixed. just use cli to update.

```
kirby plugin:update bnomei/kirby-styledmap
```
