Validate and process a Geolocation history export
Validate Geolocation CSV headers, UTC timestamps and accuracy locally, then create a minimized summary for an approved investigation window.
Validate and process a Geolocation history export
Validate the exported file before using location history in a report or incident workflow. This guide builds a local Python check that reads the documented CSV columns, rejects ambiguous or malformed records and produces a small summary for an approved time window. It leaves the original file unchanged and does not send data to a service.
The workflow is for an IT analyst or developer supporting a company-device investigation. The useful outcome is a reproducible answer to “which recorded positions fall within this window, and how many include an accuracy value?” It does not establish a device's current location, prove a recovery or confirm that a notification was delivered.
Prepare the export and its owner
Use an account authorized to read and export the intended device's location history. Confirm the device identifier, company ownership and case scope before opening Location. Assign a response owner who will interpret the result and decide whether another observation is necessary; the person running an importer should not silently broaden collection or recovery permissions.
Choose an approved local storage location, define who can read the file and record the investigation's UTC start and end. Keep the original export under the organization's retention and disposal rules. A selected row, a screen filter or a date window you intend to investigate does not establish the scope of the downloaded file.
The illustration shows one page of a larger history. The export implementation described in Geolocation availability and data offers CSV and Excel (XLSX) and exports the selected device's full retained history. It is not limited to the visible page, selected row or investigation window. Confirm the actual file and the behavior of your deployed version before automating a process. This example handles CSV; it does not parse XLSX or define a retention guarantee.
The current public Trio OpenAPI reference does not document a Geolocation endpoint. This guide starts with an authorized exported file. It does not introduce an API URL, SDK method, Inventory-key permission or supported unattended-download mechanism.
Check the file's schema
The CSV header for the version covered here is:
Recorded At (UTC),Latitude,Longitude,Accuracy (m),Address
| Column | Validation and interpretation |
|---|---|
Recorded At (UTC) | An explicit UTC timestamp for the recorded position. Preserve the date and fractional seconds. It is not a command acknowledgment or receipt timestamp. |
Latitude | A finite decimal value from −90 through 90. Keep latitude and longitude in their named columns. |
Longitude | A finite decimal value from −180 through 180. Decimal formatting does not establish spatial accuracy. |
Accuracy (m) | A nonnegative available accuracy value in meters, or blank when unknown. A blank value must not become zero. |
Address | Optional readable text. A comma can be part of a quoted CSV field. An absent address does not make otherwise valid coordinates unusable. |
The console's Source column is absent from this CSV schema. Do not add GPS to every imported row, infer a sensor from coordinate precision or rename the screen's When label into an invented file field. The reviewed backend exporter formats coordinates to six decimal places; the validator accepts valid decimal representations without requiring fixed width. Extra decimal digits in a file are not extra measurement accuracy.
Keep three clocks separate
An action can be accepted, a device response can be received and a position can be recorded at different times. Nearby repeated observations can be combined with an existing stored position. Consequently, a device can answer a request while the stored position timestamp remains unchanged.
This CSV contains recorded positions. It does not carry the full command lifecycle, a separate response-received timestamp, notification receipts or a geofence event stream. Use the relevant product state for those questions. Do not count CSV rows as Locate now answers, use a missing new row to declare a failed request or reconstruct an exact route between observations.
Convert an incident window to UTC deliberately. The example uses an inclusive start and exclusive end: start <= recorded time < end. Adjacent daily windows then do not count midnight twice. This is a local processing convention, not a date-range parameter sent to Trio.
Run the local validator
Use a maintained Python 3 installation; the example was checked with Python 3.12 and uses only its standard library. Save the code as validate_geolocation_export.py. There are no package-install, network or credential steps.
The code validates every input row before completing the summary, including rows outside the selected window. It accepts a UTF-8 byte-order mark, preserves quoted CSV fields and treats unknown accuracy separately from a supplied zero. It rejects unexpected headers, nonfinite numbers, invalid coordinates, malformed rows and timestamps without explicit UTC.
For predictable review, this example accepts fractional seconds up to six digits and imposes local guards of 10 MiB and 100,000 rows. These are example-processing safeguards, not Trio product limits. If a real export exceeds them or uses a different timestamp representation, stop and review the importer rather than silently truncating the file or changing its schema.
#!/usr/bin/env python3
"""Validate an authorized CSV locally; emit a minimized summary, never coordinates."""
import argparse
import csv
import json
import re
import sys
from datetime import datetime
from decimal import Decimal, InvalidOperation
from pathlib import Path
HEADERS = ["Recorded At (UTC)", "Latitude", "Longitude", "Accuracy (m)", "Address"]
MAX_BYTES = 10 * 1024 * 1024 # Example processing guard, not a Trio product limit.
MAX_ROWS = 100_000 # Example processing guard, not a Trio product limit.
UTC_TEXT = re.compile(r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]{1,6})?(?:Z|\+00:00)\Z")
class ExportError(ValueError):
pass
def utc(value, label):
if not isinstance(value, str) or not UTC_TEXT.fullmatch(value):
raise ExportError(f"invalid {label}; use an explicit UTC timestamp")
try:
return datetime.fromisoformat(value.replace("Z", "+00:00"))
except ValueError:
raise ExportError(f"invalid {label}; check the calendar date") from None
def number(value, label, low, high=None):
try:
parsed = Decimal(value.strip())
except (InvalidOperation, ValueError):
raise ExportError(f"invalid {label}") from None
if not parsed.is_finite() or parsed < low or (high is not None and parsed > high):
raise ExportError(f"invalid {label}")
return parsed
def stamp(value):
return value.isoformat().replace("+00:00", "Z") if value else None
def summarize(path, start, end):
if start >= end:
raise ExportError("window start must be earlier than window end")
if path.stat().st_size > MAX_BYTES:
raise ExportError("input exceeds this example's local byte limit; review before processing")
total = selected = known = 0
oldest = newest = None
with path.open("r", encoding="utf-8-sig", newline="") as source:
reader = csv.DictReader(source, strict=True)
if reader.fieldnames != HEADERS:
raise ExportError("unexpected CSV headers; review the export version")
for row in reader:
total += 1
if total > MAX_ROWS:
raise ExportError("input exceeds this example's local row limit; review before processing")
try:
if None in row or any(value is None for value in row.values()):
raise ExportError("wrong number of columns")
recorded = utc(row["Recorded At (UTC)"], "Recorded At (UTC)")
number(row["Latitude"], "Latitude", Decimal(-90), Decimal(90))
number(row["Longitude"], "Longitude", Decimal(-180), Decimal(180))
accuracy = row["Accuracy (m)"].strip()
if accuracy:
number(accuracy, "Accuracy (m)", Decimal(0))
except ExportError as error:
raise ExportError(f"CSV line {reader.line_num}: {error}") from None
# Validate every input row, then apply a local half-open time window.
if start <= recorded < end:
selected += 1
known += bool(accuracy)
oldest = recorded if oldest is None else min(oldest, recorded)
newest = recorded if newest is None else max(newest, recorded)
return {
"window_start_utc": stamp(start), "window_end_exclusive_utc": stamp(end),
"input_rows": total, "selected_rows": selected,
"rows_with_known_accuracy": known, "rows_without_accuracy": selected - known,
"oldest_selected_position_utc": stamp(oldest),
"newest_selected_position_utc": stamp(newest),
}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("csv_path", type=Path)
parser.add_argument("--start", required=True, help="inclusive UTC position time")
parser.add_argument("--end", required=True, help="exclusive UTC position time")
args = parser.parse_args()
try:
summary = summarize(args.csv_path, utc(args.start, "window start"), utc(args.end, "window end"))
except ExportError as error:
print(f"Validation stopped: {error}", file=sys.stderr)
return 2
except (OSError, UnicodeError, csv.Error):
print("Validation stopped: input could not be read as a supported UTF-8 CSV.", file=sys.stderr)
return 2
print(json.dumps(summary, indent=2)) # Nothing is emitted before full validation.
return 0
if __name__ == "__main__":
raise SystemExit(main())
Run it against an authorized file named history.csv:
python3 validate_geolocation_export.py history.csv \
--start 2026-11-27T00:00:00Z \
--end 2026-11-28T00:00:00Z > summary.json
The checked illustrative file contains 48 valid records, of which five fall within that UTC window. Its summary contains counts, the chosen window and the oldest and newest selected position times. Your export and result can differ. No latitude, longitude, address or device identifier is copied into the summary. The program writes no partial summary when a later row fails validation.
The output field names are local example fields, not a Trio API response. A valid empty selection means no validated records matched the chosen window; it does not prove that the device had no activity, that collection was disabled or that the file contains every observation ever made.
Handle failures without losing evidence
| Observation | Next step and owner |
|---|---|
| Export is unavailable or restricted | Ask the authorized administrator to check the device, capability and export permission. Do not work around the restriction with a private endpoint. |
| Header validation fails | Keep the original restricted file. The integration owner should compare its schema with the matching product reference before changing the importer. |
| A value or row is invalid | Retain the original. Record the reported line and column, without copying its location values into a general ticket. Investigate the producer or file handling before retrying. |
| No rows match | Check UTC conversion, inclusive/exclusive boundaries, selected device and available retained history. Do not substitute an unrelated device's records. |
| Accuracy is missing or too broad | Treat the spatial conclusion as uncertain. The response owner decides whether a supported new observation or another approved source is needed. |
| The file exceeds a local guard | Review size, resource handling and the downstream data need. Do not drop rows merely to make validation pass. |
Keep addresses and other free-text fields as untrusted data. This script never evaluates them and omits them from its output. If you later create spreadsheet output, review formula-injection handling rather than opening or copying untrusted cells as executable formulas. Do not paste the raw export into a general chat, public issue or AI prompt.
Complete the handoff and cleanup
Give the response owner the minimized summary, device reference in the approved case system, UTC window, file checksum, importer revision and any known uncertainty. Record the identity and scope checks separately from the parsed row count. A reproducible summary is useful evidence for a decision; it is not a legal conclusion or proof of physical recovery.
Completion requires an authorized source, exact reviewed headers, valid values across the full file, deliberate UTC boundaries and an explicit interpretation of unknown accuracy. Retain only the working copies the case needs and dispose of temporary copies under your organization's policy. Turning reporting off does not itself delete retained history or copies already exported.
For the product workflow, see Export a device's location history. For request and timestamp interpretation, see Read a device location, request an update and inspect history. For boundary-specific questions, use Geofences and event behavior rather than deriving events from a position CSV.

