💾 Archived View for gmi.bacardi55.io › blog › 2017 › 02 › 21 › kalliope-googlemaps-neuron captured on 2023-07-22 at 16:47:00. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Kalliope GoogleMaps neuron

Posted on 2017-02-21

Introduction

If you follow me on twitter or github, you may have seen this new neuron coming, otherwise, let me introduce to you the Google Maps neuron[1] :)

1: https://github.com/bacardi55/kalliope-gmaps

The goal as you can guess is to leverage the Google Maps API to get direction, distance or direction from an origin point to a destination (it doesn't handle multi origin or destination yet).

What can you do ?

The synapse has a lot of options, so you can set your transportation mode (driving, walking, tube, …), the language, the units system, … Read the readme file[2] as it contains more information (and more up to date).

2: https://github.com/bacardi55/kalliope-gmaps/blob/master/README.md

Installation

Neuron

Usual neuron installation:

  kalliope install --git-url https://github.com/bacardi55/kalliope-gmaps.git

Will install the neuron and the [google maps services python library)[https://googlemaps.github.io/google-maps-services-python/docs/2.4.5/[3])

3: https://googlemaps.github.io/google-maps-services-python/docs/2.4.5/

Synapse

Get the distance and time between 2 locations

  - name: "Gmaps-distance"
    signals:
      - order: "distance between {{origin}} and {{destination}}"
    neurons:
      - gmaps:
          gmaps_api_key: "*********"
          mode: "driving"
          language: "en"
          units: "metric"
          traffic_model: "pessimistic"
          args:
            - origin
            - destination
          file_template: "templates/en_gmaps.j2"

Get the address of a place by its name

  - name: "Gmaps-place-address"
    signals:
      - order: "get address of {{search}}"
    neurons:
      - gmaps:
          gmaps_api_key: "******************"
          language: "en"
          units: "metric"
          args:
            - search
          file_template: "templates/en_gmaps.j2"

You can find more up to date example on the github readme page

template

Here is a single template file to handle multiple use cases:

  {% raw %}
  {% if status == "KO" %}
      Sorry, but the search didn't work, Sir
  {% elif status == "OK" %}
      {% if search %}
          {% if origin %}
              Distance between {{ origin }} and {{ search }} is {{ distance }}.
              You need around {{time}} to go there
              {% if time_traffic %}
                  You need to plan {{time_traffic}} with the current traffic
              {% endif %}
          {% else %}
              Address of {{search}} is {{destination}}
          {% endif %}
      {% elif destination %}
          Distance between {{oringi}} and {{destination}} is {{distance}}
          You need about {{ time }} to go there.
          {% if time_traffic %}
            Plan {{ time_traffic }} with current traffic.
          {% endif %}
      {% endif %}

      {% if directions %}
          To go to {{destination}}, you need
          {% for direction in directions %}
              {{ direction }}
          {% endfor %}
      {% endif %}

  {% endif %}
  {% endraw %}

Of course, you can simplify by splitting it into several templates depending on the arguments you send.

What's next

Obviously, the Gmaps API is so rich that the possibility for this neuron are limitless… But at least this first version let you do the basics…

What I have in mind for next updates:

As always, ideas or pull requests are more than welcome!

/gemlog/

Send me a gemini mention

send me an email!