Visualizing Filming Locations with the TomTom Maps SDK for Web
Shannon Stroud·Oct 22, 2019

Visualizing Filming Locations with the TomTom Maps SDK for Web

Shannon StroudShannon Stroud
Shannon Stroud
Shannon Stroud is a Senior Digital Marketer part of the Developer Relations Team at TomTom. She has been at TomTom since the beginning of 2019. Prior to her role at TomTom, she’s held digital marketing and communication positions at different tech companies over the last five years, where she has been responsible for social media, content creation and strategy, community building, copywriting and PR. At TomTom, she is focused on content strategy for digital channels and growing the developer community. She's a word nerd, creative and loves overusing emojis. In office, you'll find her blogging, tweeting, drinking cup after cup of coffee and watering her tiny office plant.
Oct 22, 2019 · 12 min read

Our location services and the Maps SDK for Web make it easy for programmers to create location-aware visualizations. In this tutorial we’ll walk through an application that uses a public data set of film locations in New York City to display these locations and information about them on a map. We'll also look at the techniques you can use to understand and convert other data sources to similar mapping displays, even if they don't include latitude and longitude coordinates.

Visualizing Filming Locations with Maps SDK for Web

Converting a data set with location information into a visual representation of the data used to be a task for specialized software. TomTom location services and the TomTom Maps SDK for Web make it easy for programmers to create location-aware visualizations.

In this tutorial we’ll walk through an application that uses a public data set of film locations in New York City to display these locations and information about them on a map. The same technique could be used to display data from a variety of public or proprietary data sets. In this tutorial you will do the following:

  • Read information and location data from a public or proprietary data set.

  • Create a map marker and popup to display information for each valid data point.

  • Use TomTom location services to geocode locations that are missing lat/long coordinates.

Creating your map

To get started, you'll need the following:

Download and unzip the TomTom Maps for SDK Web Standalone functional example.

Next, download the XML file from Filming Locations (Scenes from the City), then save this XML file into a new directory called data in the root directory of your unzipped Standalone function example files.

Create a new file called nyc-movie-locations.html that contains the following web page markup, then save this new file beside the existing index.html file into the root directory of your unzipped Standalone function example files.

1<!DOCTYPE html>
2    <html class='use-all-space'>
3    <head>
4        <meta http-equiv='X-UA-Compatible' content='IE=Edge' />
5        <meta charset='UTF-8'>
6        <title>My Map</title>
7        <meta name='viewport' content='width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no'/>
8        <link rel='stylesheet' type='text/css' href='./sdk/maps.css'/>
9        <link rel="shortcut icon" href="/favicon.png">
10        <link rel="apple-touch-icon" href="/favicon.png">
11        <script src='./sdk/maps-web.min.js'></script>
12        <script src='./sdk/services-web.min.js'></script>
13        <script src=''></script>
14        <style>
15        #map {
16            width: 100vw;
17            height: 100vh;
18        }
19        </style>
20    </head>
21    <body>
22        <div id='map' class='map'></div>
23        <script>
24            // Coordinates of New York City - offset a little to centre the map
25            var startPoint = [[-74.0060 - 0.01, 40.7128 + 0.01]];
27            // enter your own API key here
28            var yourKey = '<your-tomtom-API-Key>';
30            // create a map, centered and zoomed
31            tt.setProductInfo('<your-product-name>', '<your-product-version>');
32            var map={
33                                key: yourKey,
34                                container: 'map',
35                                zoom: 10.7,
36                                center: startPoint[0],
37                                style: 'tomtom://vector/1/basic-main'
38                            });
40            // add some controls
41            map.addControl(new tt.FullscreenControl());
42            map.addControl(new tt.NavigationControl());
44            // setup popup boundaries
45            var markerHeight = 50, markerRadius = 10, linearOffset = 25;
46            var popupOffsets = {
47                'top': [0, 0],
48                'top-left': [0,0],
49                'top-right': [0,0],
50                'bottom': [0, -markerHeight],
51                'bottom-left': [linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
52                'bottom-right': [-linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
53                'left': [markerRadius, (markerHeight - markerRadius) * -1],
54                'right': [-markerRadius, (markerHeight - markerRadius) * -1]
55            };
57            // extract data from a given row and column of data source
58            function extractData(source, row, column, tab){
59                // alter location to extract data depending on tab of spreadsheet
60                var result = (tab==1) ? source.querySelector("Workbook > Worksheet:nth-child(5) > Table > Row:nth-child(" + row + ") > Cell:nth-child("+column+") > Data")
61                                    : source.querySelector("Workbook > Worksheet:nth-child(7) > Table > Row:nth-child(" + row + ") > Cell:nth-child("+column+") > Data");
62                // get innerHTML if a valid result, if valid, clean up data here.
63                return result == null ? "" : result.innerHTML.trim().replace('n/a','').replace('N/A','');
64            }
66            function createMarkerAndPopup(source, row, tab){
67                // cater for two different formats for tab 1 vs tab 3
68                var col = (tab==1)? [1,2, 6,7,8,9,10,11,12,13,14,15,16]  // tab 1
69                                : [1,2,21,5,6,7, 8, 9,10,11,12,13,14]; // tab 3
71                var Film = extractData(source,row,col[0],tab);
72                var Year = extractData(source,row,col[1],tab);
73                var Artist_Credit = extractData(source,row,col[2],tab);
74                var Director_Filmmaker_Name = extractData(source,row,col[3],tab);
75                var Director_Filmmaker_IMDB_Link = extractData(source,row,col[4],tab);
76                var Location_Display_Text = extractData(source,row,col[5],tab);
77                var LATITUDE = extractData(source,row,col[6],tab);
78                var LONGITUDE = extractData(source,row,col[7],tab);
79                var Borough = extractData(source,row,col[8],tab);
80                var Neighborhood = extractData(source,row,col[9],tab);
81                var Scene_Type = extractData(source,row,col[10],tab);
82                var Media = extractData(source,row,col[11],tab);
83                var IMDB_LINK = extractData(source,row,col[12],tab);
85                if (tab==3){
86                    // build a location to geocode
87                    var loc = (Location_Display_Text + ' ' + Borough + ' ' + Neighborhood).trim();
88                    // don't try to geocode blank entries
89                    if(loc!='') {
90                        $.get( ""+
91                                    loc.trim()+
92                                    ".xml?typeahead=false&limit=1&countrySet=US&lat=40.7128&lon=-74.0060&radius=10000&topLeft=41%2C-174&btmRight=40%2C-73.5&key="+
93                                    yourKey, function(data,status){
94                            // only grab results when successful
95                            if(status=='success'){
96                                var results = data.querySelector("response > summary > numResults");
97                                if (results != null && results.innerHTML == '1'){
98                                    LATITUDE = data.querySelector("response > results > item > position > lat").innerHTML;
99                                    LONGITUDE = data.querySelector("response > results > item > position > lon").innerHTML;
100                                    console.log(loc+' Geocoded result: '+LATITUDE+ ','+LONGITUDE);
101                                }
102                            }
103                        });
104                    }
105                }
107                // only show data
108                if (!isNaN(LATITUDE) && !isNaN(LONGITUDE)){
109                    // coordinate for the map marker
110                    var state = {
111                            center: {
112                                lat:  LATITUDE,
113                                lng: LONGITUDE
114                            },
115                            coordinates: null,
116                            selectedAddress: null
117                        };
119                    // HTML content for the popup
120                    var html = "<table>" +
121                                "<tr><th>" + Media + "</th><td><a href='" + IMDB_LINK +"' target='_blank'>" + Film + "</a></td></tr>"+
122                                "<tr><th>Year</th><td>" + Year + "</td></tr>" +
123                                "<tr><th nowrap>" + Artist_Credit + "</th>" +
124                                "<td><a href='" + Director_Filmmaker_IMDB_Link + "' target='_blank'>" + Director_Filmmaker_Name + "</a></td></tr>"+
125                                "<tr><th>Location</th><td>" + Location_Display_Text.replace("&amp;", "&")
126                                                                                    .replace("&lt;br&gt;", ", ")
127                                                                                    .replace("&lt;br&gt;", ", ") + "</td></tr>" +
128                                (Scene_Type != "" ? "<tr><th>Scene</th><td>" + Scene_Type + "</td></tr>" : "") +
129                               "</table>";
131                    // create a popup
132                    var popup = new tt.Popup({offset: popupOffsets, className: 'my-class'})
133                            .setLngLat(
134                            .setHTML(html)
135                    .addTo(map);
137                    // create a map marker and link to the popup
138                    var marker = new tt.Marker()
139                    .setLngLat(
140                    .setPopup(popup)
141                    .addTo(map);
142                }
143            }
145            // read the XML data file, extract the data and create a marker+popup for each location
146            $.get("data/Interactive_Map_Data.xml", function (xml) {
147                // console.log(xml);
149                // read from 1st spreadsheet tab (231 rows)
150                for (var i=22;i<254;i++) {
151                    createMarkerAndPopup(xml, i, 1);
152                }
153                // read from 3rd spreadsheet tab (7 rows)
154                for (var i=6;i<14;i++) {
155                    createMarkerAndPopup(xml, i, 3);
156                }
157            });     
158        </script>
159    </body>
160    </html>  

Here you’ll need your own free API key.

If you haven’t got one yet just follow the steps Create your API Key now at this tutorial.

Next edit your map file nyc-movie-locations.html to include your own API key (in var yourKey = '<your-tomtom-API-Key>';), as well as an application name and application version.

Finally, to be able to view the new map we’ll run a simple HTTP server. Navigate to the directory containing the example.

We're going to install a light-weight Node.js http-server (note that you might need to run this command with admin/root privileges):

1npm install --global http-server

Then just simply run the following command to start the server:


Now you can view your map page by pointing your browser to URL http://localhost:8080/nyc-movie-locations.html

Here it is:


Click on a map marker to view the popup information. Click on a movie or director link to view more information from IMDB in another window. You can use the zoom or full screen controls, or mouse zoom/drag to navigate as required.

Reviewing The Data Source

Thinking of creating similar applications for yourself? Here’s a few tips to help you see if a given data source is suitable, as well as some background information on how this particular data set was analyzed and used here.

The dataset Filming Locations (Scenes from the City) happens to be a spreadsheet saved as XML. Almost any data source could be used including JSON, plain text, CSV, XML, data objects from a database, or an API call.

The important thing is that each data point includes the relevant information you want to map and some sort of location information — ideally latitude and longitude coordinates or at least an address, even if just a suburb or city.

The data source used for this application happens to have all of this. Here’s the first few rows in the first tab of the spreadsheet, as viewed from Excel:


You could also view the XML in a text editor, and this might be all you need if it is a straightforward XML file.

If your data source is missing latitude and longitude information, but includes street address or suburb/place name information, then it is possible to use geocoding, a process where the location is converted to a latitude and longitude, to create the necessary latitude and longitude coordinates for mapping the data points.

Notice the third tab of the spreadsheet called “Items without location”, here’s an example of data entries without latitude and longitude information. Later in the tutorial we’ll see how we can use geocoding services, which are a part of TomTom location services, to make this data usable as well.


This following ‘trick’ can help make analysis and extraction of any data source, documented or not, much easier.

Inside the nyc-movie-locations.html page where we read the XML block, just uncomment the console.log line, then comment out the remaining code in the block, leaving just the console.log statement active as shown below:

1$.get("data/Interactive_Map_Data.xml", function (xml) {
2                console.log(xml);
3                // // read from 1st spreadsheet tab (231 rows)
4                // for (var i=22;i<254;i++) {
5                //  createMarkerAndPopup(xml, i, 1);
6                // }
7                // // read from 3rd spreadsheet tab (7 rows)
8                // for (var i=6;i<14;i++) {
9                //  createMarkerAndPopup(xml, i, 3);
10                // }
11            });

Save your changes, then view your map page at URL http://localhost:8080/nyc-movie-locations.html. We’ll use the Chrome browser’s debug mode to help us explore the data in the XML file (or other data source) and this in turn will help us see how the data is structured as well as help us extract the information we need to create our map. Most browsers include developer console features similar to the example shown here, but the specific commands and display details may differ.

In Chrome, press F12 to enter debug mode, then select the Console tab of the Chrome debugger. Refresh the page and look for an entry in the Console called #document; it should look like this:


This is the XML data we’ve just read and now logged to the console. Click on the > symbol left of #document to expand the dump of this XML data source.

The debugger allows us to drill down through the various elements of the XML file to explore the structure and find our data points. The first sections contain styles, column names, and then later the actual data we wish to use.

After you expand #document further sections appear. Expand Worksheet where it has the attribute ss:Name=”Full Map List”; this corresponds to the first worksheet tab in Excel.


Expand the Table element, then scroll down past the Column elements to the Row elements, expand the third Row element, then expand the first Cell element and finally expand the Data element inside:


Right click the Data element and navigate through Chrome’s debug menu to Copy > Copy Selector:


This is a quick way to generate the code needed to extract a particular piece of data from inside an XML document.

In the case above, the first movie title given by the selector is:

1Workbook > Worksheet:nth-child(5) > Table > Row:nth-child(22) > Cell:nth-child(1) > Data

Although the process of discovering the location of your data would be easier with good documentation or a data source you have created yourself, even moderately complex XML data such as this data set can be navigated with very little effort.

Geocoding Address Data

Now what about the third tab of the spreadsheet that was missing latitude and longitude data?

Geocoding allows us to take an address (street number, street name, and so on), or simply a place name and country, and then find the latitude and longitude of that location. Obviously, you will have better quality results if you can access a more complete address, but fortunately the TomTom Search API Geocoding endpoint is very forgiving of partial addresses and even poor typing.

For our NYC Film Locations application, the third tab has no latitude and longitude data. Instead, most rows have a mixture of filming locations, borough, and neighborhood entries. The third tab’s column ordering is a little different from the first, so we’ll use a simple lookup table, stored in an array, to vary which spreadsheet columns are copied into our final data depending on the spreadsheet tab being read at the time.

Here’s an excerpt of the code responsible for geocoding data. If we are reading data from the third tab, then we’ll build up a text string of the location, using as much address information as we can. We call the TomTom search API Geocoding endpoint and, if we get the single result requested, we’ll extract a latitude and longitude.

1if (tab==3){
2  // build a location to geocode
3  var loc = (Location_Display_Text + ' ' + Borough + ' ' + 
4    Neighborhood).trim();
5  // don't try to geocode blank entries
6  if(loc!='') {
7    $.get( ""+ loc.trim()+                          ".xml?typeahead=false&limit=1&countrySet=US&lat=40.7128&lon=-74.0060&radius=10000&topLeft=41%2C-174&btmRight=40%2C-73.5&key="+
8      yourKey, function(data,status){
9          // only grab results when successful
10        if(status=='success'){
11          var results = data.querySelector(
12            "response > summary > numResults");
13          if (results != null && results.innerHTML == '1'){
14            LATITUDE = data.querySelector(
15              "response > results > item > position > lat").innerHTML;
16            LONGITUDE = data.querySelector(
17              "response > results > item > position > lon").innerHTML;
18            console.log(loc+' Geocoded result: '+LATITUDE+ ','+LONGITUDE);
19          }
20        }
21      });
22  }

To see only geocoded data, just comment out the loop of data from the first tab and leave the loop around the data from the third tab.


In this tutorial we’ve found out how to analyze an XML data file as well as how to extract location data and other information from our data source. We also saw how to display this data as map-markers and popups on a map and how to geocode data when we are supplied with geographical coordinates.

Where next? Try using these same techniques to map data for your company, community or other uses.

You could also enhance your map to include a grand tour of selected New York Movie locations, complete with traffic flow and routing. Many features are demonstrated in the sample files included with Tom Tom Maps for SDK Web Standalone functional example that you downloaded to build this application. Just look in the \pages\examples\html folder of the unzipped files and you’ll find dozens of functional samples full of great ideas. To get them running, just edit them and add a copy of your free API key.

Get the developer newsletter.
No marketing fuff. Tech content only.

* Required field. By submitting your contact details to TomTom, you agree that we can contact you about marketing offers, newsletters, or to invite you to webinars and events. We could further personalize the content that you receive via cookies. You can unsubscribe at any time by the link included in our emails. Review our privacy policy.