Go to page content

Geocoding and mapping in Zotonic

Marc Worrell— 25 April 2012

For the upcoming 0.9 release of Zotonic we are adding more geo-support.

The new mod_geomap module brings geo-support to Zotonic.

Whenever a resource (page) is saved, it checks if there is an address filled in and will use the Google Maps geocode API and the OpenStreetMap Nominatim API to find the latitude and longitude for that address. That is, when there is not yet a coordinate filled in by hand.

In the admin interface we added OpenStreetMap instead of the Google Maps interface. Using the excellent OpenLayers Javascript library we added an interface to easily define the location for a page. You have the option to:

  • Leave the location blank, in that case mod_geomap will do the geocoding on the basis of the address you filled in.
  • Manually enter a latitude and longitude.
  • Select the location belonging to the currently filled in address.
  • Select your current location using the geoposition API of your browser.
  • Click on the map to select a location.

Plenty of choices.

QuadTile encoding of coordinates

For searching we encode the latitude and longitude into a single integer using the QuadTile algorithm. This is done with 31 bits precision per coordinate, which gives a resolution of about 10 centimeter.

The nice thing of using QuadTile is that location searches become simple integer range based queries. Which are easy for almost all indexed data stores.

Show a static map

You can show a static HTML version of a map. Just supply which location you want to show and the HTML is generated:

{% geomap_static id=id %}

This generates a static HTML map using OpenStreetMaps tiles. A marker is included to pinpoint the exact location on the map.

You can force the tile size to something smaller than the standard 256 pixels and vary the number of tiles horizontally or vertically.

Unlike other static map solutions we make use of the OpenStreetMaps tiles. The code calculates the tiles needed and the HTML is generated using a template. Because of this you can use your own template, another tile server, or add behavior to the marker image.