Where is humitos?

This page is a translation from the Spanish one and maybe it’s outdated. Please, read the Spanish version to be up to date.

This map is useful to know where I approximately am at this moment and which is my planned route for the next days/weeks/months. The map’s goal is to be in touch with people next to me (or my planned route) so we can coordinate something related with the project (or anything of mutual interest) and organize to see each other in the proximities.

  • rutaplanned route for months January, February and March 2016
  • destinos destinies we want to go in those months
  • visitados places already visited by the project since its start

How this map works?

Briefly speaking, when I get connected to the Internet a signal is sent to this web site with the position where I am at the moment I get connected, using the Internet connection to know my location.

This process is automatic which allows it to be really up to date with my current location instead of update it every time I change position by myself.


How this map exactly works… ?

In deep, I use javascript to download the my-position.json file where the coordinates of my current position are and show them into the map:

donde-esta-humitos/geolocation.js (Source)

        $.getJSON("/assets/data/my-position.json", function(point){
            var icon = L.icon({
                iconUrl: '/assets/img/marker-car.png',
                shadowUrl: '/assets/img/marker-car-shadow.png',

                iconSize:     [64, 36], // size of the icon
                shadowSize:   [82, 49], // size of the shadow
                iconAnchor:   [32, 0],   // point of the icon which will correspond to marker's location
                shadowAnchor: [28, 10],   // the same for the shadow
                popupAnchor:  [0, -10] // point from which the popup should open relative to the iconAnchor
            });

            // center the map in my position
            map.setView(point, 11);

            var marker = L.marker(point, {icon: icon}).addTo(map);
            marker.bindPopup("<b><em>humitos</em></b> está <em>por</em> aquí!").openPopup();
        });
  1. Download my-position.json
  2. Create the car’s icon
  3. Add the point inside my-position.json to the map
  4. Center the map in that position

That my-position.json is generated by a Python script:

donde-esta-humitos/geolocation.py (Source)

def calc_my_position_ip(output=MY_POSITION_FILENAME):
    setup_output(output)
    logger.info('Waiting %s seconds...', WAIT_BEFORE_QUERY)
    time.sleep(WAIT_BEFORE_QUERY)
    logger.info('Querying the server about my ip...')
    response = geocoder.ip('me')
    logger.info('LatLng: %s', response.latlng)
    logger.info('Place: %s', response.address)

    return calc_my_position_address(response.address, output)


def calc_my_position_address(address, output, upload=True):
    logger.info('Querying the server about "%s"...', address)
    response = geocoder.osm(address)
    logger.info('LatLng: %s', response.latlng)
  1. It uses the geocoder library to get the coordinates from my current IP
  2. It logs all the process to know what happend in case something went wrong
  3. Saves the latitude and longitude into my-position.json
  4. Uploads the new my-position.json (with the new coordinates) to the server using scp

Note

I’m using time.sleep(WAIT_BEFORE_QUERY) because I need to wait for NetworkManager to get connected to the Internet.

That script is executed by NetworkManager when it’s connected to a network.

donde-esta-humitos/geoblog (Source)

#!/bin/bash
# /etc/NetworkManager/dispatcher.d/geoblog

IF=$1
STATUS=$2

cd /home/humitos/Source/argentinaenpython.com.ar/web

case "$2" in
    up)
    logger -s "NM Script 'geoblog' triggered"
    /usr/bin/fades --python /usr/bin/python3 /home/humitos/Source/argentinaenpython.com.ar/web/geolocation.py --me & \
    exit 0
    logger -s "NM Script 'geoblog' finished"
    ;;
    *)
    ;;
esac

Note

This script need to be copied in /etc/NetworkManager/dispatch.d/geoblog and root has to be the owner of it to be executed by NM.

Basically, it execute the Python script geolocation.py if the interphase is up.

Note

It’s needed to add & to the final of each command because NetworkManager has a bug that kills all the scripts if they have a delay greater than 3 seconds, and mine takes more than that because I need to check something on the Internet.

That’s all!