From 7494a49238520fbf05168130420db96825e244ce Mon Sep 17 00:00:00 2001 From: Malte Franken Date: Mon, 7 Oct 2019 18:49:00 +1100 Subject: [PATCH] Normalize longitude to the range between -180 to +180 degrees (#3872) * normalize longitude to the range between -180 to +180 degrees * only normalize longitude if out of valid range --- src/components/map/ha-location-editor.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/map/ha-location-editor.ts b/src/components/map/ha-location-editor.ts index 9f3d45c01a..0d4133b832 100644 --- a/src/components/map/ha-location-editor.ts +++ b/src/components/map/ha-location-editor.ts @@ -77,7 +77,12 @@ class LocationEditor extends LitElement { } private _updateLocation(latlng: LatLng) { - this.location = this._ignoreFitToMap = [latlng.lat, latlng.lng]; + let longitude = latlng.lng; + if (Math.abs(longitude) > 180.0) { + // Normalize longitude if map provides values beyond -180 to +180 degrees. + longitude = (((longitude % 360.0) + 540.0) % 360.0) - 180.0; + } + this.location = this._ignoreFitToMap = [latlng.lat, longitude]; fireEvent(this, "change", undefined, { bubbles: false }); }