From bf870f32eb38287f5de14a98c3adce81b2020124 Mon Sep 17 00:00:00 2001 From: itskovacs Date: Thu, 24 Jul 2025 19:33:46 +0200 Subject: [PATCH] :zap: Fix Google Maps URL offset in parsing --- src/src/app/services/utils.service.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/src/app/services/utils.service.ts b/src/src/app/services/utils.service.ts index 8afa3bd..f00a509 100644 --- a/src/src/app/services/utils.service.ts +++ b/src/src/app/services/utils.service.ts @@ -50,16 +50,19 @@ export class UtilsService { } parseGoogleMapsUrl(url: string): [string, string] { - const match = url.match(/place\/(.*)\/@([\d\-.]+,[\d\-.]+)/); + // Look /place// and !3d and !4d + const placeMatch = url.match(/\/place\/([^\/]+)/); + const latMatch = url.match(/!3d([\d\-.]+)/); + const lngMatch = url.match(/!4d([\d\-.]+)/); - if (!match?.length || match?.length < 3) { - console.error("Incorrect Google Maps URL format"); + if (!placeMatch || !latMatch || !lngMatch) { + this.toast("error", "Error", "Unrecognized Google Maps URL format"); + console.error("Unrecognized Google Maps URL format"); return ["", ""]; } - let place = decodeURIComponent(match[1].trim().replace(/\+/g, " ")); - let latlng = match[2].trim(); - + let place = decodeURIComponent(placeMatch[1].replace(/\+/g, " ").trim()); + let latlng = `${latMatch[1]}, ${lngMatch[1]}`; return [place, latlng]; }