Adding a Map#

It can be useful sometimes to visualize lists of locations on a geographic map. Grist can do that if a table has at least a Name, Latitude, and Longitude column. Suppose we have a list of some of the largest objects in America:

List of large objects

The first step to making a map for these is to add a Custom Widget to the page:

Add custom widget

Once we set the widget to be https://gristlabs.github.io/grist-widget/map/ and give it Read table access, a map should appear:

Add map widget

Clicking around in the list of objects brings up the corresponding “pop-up” on the map. We can add other sections to taste, such as a detail “card” view of the attraction’s details. This example is available at https://public.getgrist.com/3boQPJrgFmFi/Large-in-America/m/fork.

Large in America

This example has some hidden columns related to geocoding (the process of automatically calculating coordinates from addresses). You can see these on the second page called Geocoding. They are Geocode, Address, and GeocodedAddress. If you would like to use geocoding, you’ll need these three columns, and to grant the map widget full access to your document so it can store results. Address should hold exactly what you want to pass to the geocoder. In the example, it is simply ", ".join([$City, $State]). The GeocodedAddress should be left untouched; it is a space for the geocoder to store information. Finally, Geocode is a toggle that should be turned on to automatically generate latitude and longitudes.

Geocoding

The geocoder will not touch any rows with Geocode turned off. When Geocode is turned on for a row, latitudes and longitudes are computed and stored automatically for that row using Nominatim. Nominatim’s Usage Policy allows for limited, non-bulk creative use. Robust geocoding generally requires an account with an external service and a secret API key. We expect to soon have a convenient way to store secrets in a document, and will then be able to support flexible geocoding options. If you are interested in previewing this feature, please get in touch!

Finally, if you know some HTML/CSS/JS, or have a web developer on your team, you’ll find the map custom widget simple to restyle as you like. If you need a hand, just let us know.