MagicMirrorOrg/MagicMirror · error · Error
Latitude and longitude are required
Error message
Latitude and longitude are required
What it means
validateCoordinates checks that config.lat and config.lon exist and are finite numbers before rounding them to a fixed number of decimal places. This error is thrown when either coordinate is null/undefined or not a finite number. Every weather provider calls it during initialize(), so a provider cannot start without valid coordinates.
Source
Thrown at defaultmodules/weather/provider-utils.js:163
WSW: 247.5,
W: 270,
WNW: 292.5,
NW: 315,
NNW: 337.5
};
return directions[direction] ?? null;
}
/**
* Validate and limit coordinate precision
* @param {object} config - Configuration object with lat/lon properties
* @param {number} maxDecimals - Maximum decimal places to preserve
* @throws {Error} If coordinates are missing or invalid
*/
function validateCoordinates (config, maxDecimals = 4) {
if (config.lat == null || config.lon == null
|| !Number.isFinite(config.lat) || !Number.isFinite(config.lon)) {
throw new Error("Latitude and longitude are required");
}
config.lat = limitDecimals(config.lat, maxDecimals);
config.lon = limitDecimals(config.lon, maxDecimals);
}
module.exports = {
convertWeatherType,
applyTimezoneOffset,
limitDecimals,
getSunTimes,
isDayTime,
formatTimezoneOffset,
getDateString,
convertKmhToMs,
cardinalToDegrees,
validateCoordinates
};View on GitHub (pinned to 4b4a59534f)
Solutions
- Set config.lat and config.lon as numbers, e.g. lat: 52.3738, lon: 4.8910
- If coordinates come as strings, convert with Number(value) before initialize()
- Check for typos in config keys (must be lat/lon exactly)
- Ensure the values are finite numbers, not null, undefined, NaN or Infinity
Example fix
// before
const config = { type: "current", lat: process.env.LAT, lon: process.env.LON };
provider.initialize(config);
// after
const config = { type: "current", lat: Number(process.env.LAT), lon: Number(process.env.LON) };
if (Number.isFinite(config.lat) && Number.isFinite(config.lon)) provider.initialize(config); Defensive patterns
Strategy: validation
Validate before calling
function hasValidCoordinates(config) {
return config != null
&& Number.isFinite(config.lat)
&& Number.isFinite(config.lon);
}
if (!hasValidCoordinates(config)) throw new Error("lat/lon must be finite numbers before initialize()"); Type guard
const isFiniteNumber = (v) => typeof v === "number" && Number.isFinite(v);
Try / catch
try {
provider.initialize(config);
} catch (err) {
if (err.message === "Latitude and longitude are required") {
console.error("Config missing numeric lat/lon:", config);
} else throw err;
} Prevention
- Parse env/config string coordinates with Number() before use
- Validate lat/lon with Number.isFinite in a preflight check
- Keep key names exactly lat/lon per the module docs
- Add a unit test asserting config validation for each provider
When it happens
Trigger: initialize() is called with config.lat or config.lon missing (undefined/null) or set to a non-numeric value such as a string '52.1', NaN, or Infinity.
Common situations: Config not passing lat/lon at all (weather module requires them); coordinates read from env vars or JSON as strings without parsing; typo in key names (latitude/longitude instead of lat/lon); template placeholder left unfilled.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- Latitude and longitude are required
- siteCode and provCode are required
- Unknown weather type: ${this.config.type}
- Module ${index} ("${mod.module}") uses unknown position: "${
- Invalid API response
AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31).
Data as JSON: /api/errors/8d10700db03fde1e.
Report an issue: GitHub.