Giving the user the ability to link to google maps based on latitude and longitude, allows users to get more context on interesting points in a visualisation. In this blog I will walk through how I made a clickable map that links to google maps. First we need a dataset that utilises latitude and longitude, for this blog I’ll be using weather station data that I scraped from the Bureau of Meteorology website. You can find how I scraped this data in another blog here.
First we will build a map with a point for each weather station that is sized and coloured based on the average amount of rainfall detected at that station.
Now we need to find a URL for google maps that uses latitude and longitude within the URL. https://www.google.com/maps/place/37°45’36.0″S 146°25’48.0″E is what we will use, however this needs to be URL encoded for Tableau. After URL encoding the link becomes: https://www.google.com/maps/place/37%C2%B045’36.0%22S+146%C2%B025’48.0%22E.
Unfortunately google takes Lat and Lon in degrees/minutes/seconds format, instead of decimal format. Degrees/minutes/seconds means that degrees are made up 60 minutes and minutes are made up of 60 seconds. Since latitude and longitude are almost always in decimal format, we will need to write a calculated field that converts decimal to degrees/minutes/seconds then replace the current coordinates of the URL with our converted latitude and longitude.
This formula may seem a little intimidating at first, but it’s just replacing the numbers in the original URL with the degrees/minutes/seconds of the new coordinates. In Australia, Latitude is negative, so I converted it to a positive number and specified that it was measured from the south pole ( the S in “%22S” is for south). Now all that’s left to do is add the map to a dashboard and add a URL action to the map:
Now each time a user clicks on a point on the map, it will open a new tab and show them on google maps where the point is.