MagicMirrorOrg/MagicMirror · error · Error
Latitude and longitude are required
Error message
Latitude and longitude are required
What it means
#validateConfig requires numeric lat and lon for the WeatherAPI.com query URL. It throws this Error when either value is missing or not a finite number (Number.isFinite check rejects strings, undefined, NaN, Infinity).
Source
Thrown at defaultmodules/weather/providers/weatherapi.js:66
}
#validateConfig () {
this.config.type = `${this.config.type ?? ""}`.trim().toLowerCase();
if (this.config.type === "forecast") {
this.config.type = "daily";
}
if (!["hourly", "daily", "current"].includes(this.config.type)) {
throw new Error(`Unknown weather type: ${this.config.type}`);
}
if (!this.config.apiKey || `${this.config.apiKey}`.trim() === "") {
throw new Error("apiKey is required");
}
if (!Number.isFinite(this.config.lat) || !Number.isFinite(this.config.lon)) {
throw new Error("Latitude and longitude are required");
}
}
#initializeFetcher () {
const url = this.#getUrl();
this.fetcher = new HTTPFetcher(url, {
reloadInterval: this.config.updateInterval,
headers: { "Cache-Control": "no-cache" },
logContext: "weatherprovider.weatherapi"
});
this.fetcher.on("response", async (response) => {
try {
const data = await response.json();
this.#handleResponse(data);
} catch (error) {
Log.error("[weatherapi] Failed to parse JSON:", error);View on GitHub (pinned to 4b4a59534f)
Solutions
- Add numeric lat and lon to the module config, e.g. lat: 52.52, lon: 13.405.
- Remove quotes so values are numbers, not strings.
- If coordinates come from another module, ensure they are Number() coerced before provider init.
- Verify lat/lon are in decimal degrees (not degrees-minutes-seconds).
Example fix
// before
config: { weatherProvider: "weatherapi", apiKey: "k", lat: "52.52", lon: "13.40" }
// after
config: { weatherProvider: "weatherapi", apiKey: "k", lat: 52.52, lon: 13.40 } Defensive patterns
Strategy: validation
Validate before calling
const lat = Number(config.lat), lon = Number(config.lon);
if (!Number.isFinite(lat) || !Number.isFinite(lon) || Math.abs(lat) > 90 || Math.abs(lon) > 180) {
throw new Error(`weatherapi: lat/lon must be finite decimal degrees, got ${config.lat}, ${config.lon}`);
} Type guard
function hasValidCoords(config) {
return Number.isFinite(config.lat) && Number.isFinite(config.lon);
} Prevention
- Always store lat/lon as numbers, never quoted strings, in config.
- Range-check lat [-90,90] and lon [-180,180] when coordinates come from user input or geocoding.
- If geocoding by city name, convert to coordinates before passing to this provider.
When it happens
Trigger: Module config lacks lat/lon, supplies them as strings (lat: "52.5"), sets them to null/undefined, or a location-lookup feature failed to populate them before initialize.
Common situations: Using location name instead of coordinates (some providers accept city names, weatherapi provider in MagicMirror does not), copy-pasting coordinates as strings from JSON, lat/lon defined only in a different config section.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Latitude and longitude are required
- Unknown weather type: ${this.config.type}
- siteCode and provCode are required
- apiKey is required
- [weather] Deprecation warning: Your are using the deprecated
AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31).
Data as JSON: /api/errors/ed4e80f5da5ce483.
Report an issue: GitHub.