From d528d8654054432392747c9bbff99fdb7314cbaf Mon Sep 17 00:00:00 2001 From: Malte Franken Date: Thu, 3 Oct 2019 21:17:40 +1000 Subject: [PATCH 1/2] normalize longitude to the range between -180 to +180 degrees --- src/components/map/ha-location-editor.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/map/ha-location-editor.ts b/src/components/map/ha-location-editor.ts index 9f3d45c01aad..4e733284b246 100644 --- a/src/components/map/ha-location-editor.ts +++ b/src/components/map/ha-location-editor.ts @@ -77,7 +77,9 @@ class LocationEditor extends LitElement { } private _updateLocation(latlng: LatLng) { - this.location = this._ignoreFitToMap = [latlng.lat, latlng.lng]; + // Normalize longitude if map provides values beyond -180 to +180 degrees. + const longitude = (((latlng.lng % 360.0) + 540.0) % 360.0) - 180.0; + this.location = this._ignoreFitToMap = [latlng.lat, longitude]; fireEvent(this, "change", undefined, { bubbles: false }); } From ecf602ac62e3ac008379daae7d22ef42ec2f7089 Mon Sep 17 00:00:00 2001 From: Malte Franken Date: Mon, 7 Oct 2019 01:09:34 +1100 Subject: [PATCH 2/2] only normalize longitude if out of valid range --- src/components/map/ha-location-editor.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/map/ha-location-editor.ts b/src/components/map/ha-location-editor.ts index 4e733284b246..0d4133b8327f 100644 --- a/src/components/map/ha-location-editor.ts +++ b/src/components/map/ha-location-editor.ts @@ -77,8 +77,11 @@ class LocationEditor extends LitElement { } private _updateLocation(latlng: LatLng) { - // Normalize longitude if map provides values beyond -180 to +180 degrees. - const longitude = (((latlng.lng % 360.0) + 540.0) % 360.0) - 180.0; + 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 }); }