Loading and Querying Geographic Data from SQLite
The positions are connected by their shared inner list. The first value identifies the location, while the second and third values provide the geographic coordinates associated with that name.
From Record to Map
A geographic record becomes visible on a web map through a short data pipeline. The record begins in a SQLite database. geodump.py extracts its location name, latitude, and longitude, then writes those values as executable JavaScript in where.js. When where.html loads that file in a browser, the geographic data can be used to render an interactive map.
The Database Handoff
geodump.py is the handoff point between database data and browser data. It takes records from SQLite and selects three pieces of geographic information from each record: a location name, a latitude, and a longitude. It then formats those values as nested arrays in where.js. The important idea is that the browser does not receive the original database record directly. It receives the JavaScript representation produced by geodump.py.
One Location Through the Handoff
Represent one geographic record in the format that geodump.py writes to where.js.
- 1Select values
The record contributes a location name, a latitude, and a longitude.
- 2Preserve the order
The three values are placed in one inner list in the order name, latitude, longitude.
- 3Place it in the file
The inner list becomes one entry in the outer list of
where.js.
One location is represented as a three-element nested array inside where.js.
Reading where.js
where.js is a list of lists. Each inner list represents one location and contains exactly three conceptual positions: the location name as a string, the latitude as a number, and the longitude as a number.
The positions are connected by their shared inner list. The first value identifies the location, while the second and third values provide the geographic coordinates associated with that name.
Browser Loading
After geodump.py has produced where.js, the browser-facing part of the pipeline begins. where.html loads the JavaScript file, and the geographic values are then available for rendering the interactive map. Opening where.html in a browser is enough to visualize the data when the files and data are available in the expected form.
Visibility Troubleshooting
A missing location can result from a problem at different stages of the pipeline. First determine whether the generated data exists. Then check whether the browser can load it. If the file loads, inspect the geographic values and the map display itself. This stage-by-stage approach prevents treating every visibility problem as a database problem.
Common mistake Checking only the database when nothing appears in the browser.
What it looks likeThe database may contain records, but where.js may not exist beside where.html.
Why it failsThe browser map depends on the generated JavaScript file being available to
where.html.Do this insteadVerify that where.js exists and is in the same directory as the HTML file.
Common mistake Ignoring browser errors.
What it looks likeThe page is opened, but the map remains empty and the developer console is not inspected.
Why it failsThe console can reveal errors in the browser-loading stage.
Do this insteadCheck the developer console when nothing appears.
Common mistake Treating the inner list as an unordered collection.
What it looks likeReading the longitude position as though it were the location name.
Why it failsEach inner list has a defined three-element structure: name, latitude, longitude.
Do this insteadInterpret the positions in their specified order.
Debug from left to right through the pipeline: confirm the geographic record and generated values, confirm that where.js exists, confirm that it is beside where.html, inspect the developer console, and then examine the map display.
Pipeline Practice
A location is present in the SQLite database, but no location appears after you open where.html. Describe the order in which you would investigate the pipeline.
Hints
- Begin by checking the generated JavaScript file.
- Confirm the relationship between
where.jsandwhere.html. - Use the developer console to look for browser errors.
What do you think happens?
If where.js is missing from the same directory as where.html, should opening where.html still provide the generated geographic data to the map?
Reveal answer
No, because where.html needs to load where.js.
The browser pipeline uses where.html to load the generated JavaScript. The source specifically recommends verifying that where.js exists in the same directory when nothing appears.
- 1A correct investigation follows the data rather than guessing. Check that the record was converted into
where.js, check thatwhere.jsis besidewhere.html, and inspect the developer console before drawing conclusions about the map display.
Key Takeaways
geodump.pyconverts SQLite records into executable JavaScript data.- Each
where.jsinner list represents one location as name, latitude, and longitude. where.htmlloadswhere.jsand uses its geographic values to render the interactive map.- When a location is not visible, verify the generated file, its directory, and the browser developer console.
- The complete pipeline is SQLite database,
geodump.py,where.js,where.html, and browser map.