In this article I demonstrate how a guindex style pubs map can be made using pubs data retrieved from the guindex API using the guindex python package that I created.
The guindex pubs map for a selected county can be displayed using the form below.
When the "Show Pubs Map" is pressed the selected county is extracted from the submitted form and then the guindex python package is used to get the pubs for that county.
From there, a map is created using the python package Folium. The map is centred on the average latitude and longitude of the pubs. A marker cluster is created so that pub markers (when created) group when the map is sufficiently zoomed out. We then create a marker for each pub in the county is created with the marker type depending on what information has been submitted on each pub to date.
Once the map is finished the html representation of it is added to the context dictionary within the django view which is passed to the render function. The map is then extracted from the context dictionary in the corresponding html template. Figuring out the appropriate exceptions to add to the content security policy on the live website in order to properly display the map was a bit of a headache.
The code to create the maps is available on my GitHub here. The map on the guindex page containing all of the pubs can be viewed here . If you would like to contribute to the guindex project please sign-up and start submitting data, instructions to do this are on the home page here