1

I'm currently trying to implement a Google maps via Maps plugin: https://github.com/ethercreative/simplemap

I'm following documentation entirely, using PRO version of the plugin. In the plugin settings, I've chosen Google maps style map and Geo service is Google Maps with their own API key. Everything is displaying correctly in the settings menu.

Next, I have created a field, using map field type provided from Maps plugin - and there, everything seems alright; map is showing with default location displayed.

I have section Hompage (where the client wants a Google map to be) and assigned that field to that section.

The last step should be displaying that map on the site. In the plugin documentation, it says that I need to simply call that field via twig.

I was using {{ craft.entries().section("home").one().mapGoogle }} (mapGoogle is a field handle)but it is showing me an error Object of class ether\simplemap\models\Map could not be converted to string

I'm keep getting different errors, but it all came to that last one which I cannot solve, and I don't know what am I doing wrong. Did I miss something in the installation or documentation? Or, simply I don't know how to use twig tags :)

EDIT: When I'm using embed part from the plugin documentation nothing happens.

Dumping this variable I'm getting this info:

object(ether\simplemap\models\Map)[724]
  public 'id' => null
  public 'ownerId' => int 239
  public 'ownerSiteId' => int 1
  public 'fieldId' => string '37' (length=2)
  public 'zoom' => int 13
  public 'distance' => null
  public 'lat' => null
  public 'lng' => null
  public 'address' => string '' (length=0)
  public 'parts' => 
    object(ether\simplemap\models\Parts)[871]
      public 'number' => string '' (length=0)
      public 'address' => string '' (length=0)
      public 'city' => string '' (length=0)
      public 'postcode' => string '' (length=0)
      public 'county' => string '' (length=0)
      public 'state' => string '' (length=0)
      public 'country' => string '' (length=0)
      public 'planet' => string 'Earth' (length=5)
      public 'system' => string 'the Solar System' (length=16)
      public 'arm' => string 'Orion Arm' (length=9)
      public 'galaxy' => string 'Milky Way' (length=9)
      public 'group' => string 'the Local Group' (length=15)
      public 'cluster' => string 'Virgo Cluster' (length=13)
      public 'supercluster' => string 'Laniakea Supercluster' (length=21)
  public 'what3words' => null
  private '_errors' (yii\base\Model) => null
  private '_validators' (yii\base\Model) => null
  private '_scenario' (yii\base\Model) => string 'default' (length=7)
  private '_events' (yii\base\Component) => 
    array (size=0)
      empty
  private '_eventWildcards' (yii\base\Component) => 
    array (size=0)
      empty
  private '_behaviors' (yii\base\Component) => null
1

The field is returning a Map object, you then need to call what you want from there. The relevant documentation parts are:

Embedded map - https://docs.ethercreative.co.uk/maps/rendering/embed/#from-a-map-field

Static map - https://docs.ethercreative.co.uk/maps/rendering/static/#from-a-map-field

Based on your code and dump:

{# Fetch the Map object #}
{% set myMapField = craft.entries()
    .section("home")
    .one()
    .mapGoogle %}

{# The below should render Milky Way based on your dump #}
{{ myMapField.galaxy }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.