diff --git a/docs/usage_tips.md b/docs/usage_tips.md index 9bfb8d2..d10c03e 100644 --- a/docs/usage_tips.md +++ b/docs/usage_tips.md @@ -26,6 +26,12 @@ Supported formats include examples like: - `37°46'29.64" N, 122°25'9.84" W` - `37°46.494' N, 122°25.164' W` +### Plus Code Parsing + +You can paste a [Plus Code](https://maps.google.com/pluscodes/) into the `latitude` input when creating a Place. + +Example: `849VCWC8+R9` + ## Trip ### Display a day itinerary diff --git a/src/package.json b/src/package.json index 9e50c2e..7067de1 100644 --- a/src/package.json +++ b/src/package.json @@ -28,6 +28,7 @@ "leaflet": "^1.9.4", "@types/leaflet": "^1.9.19", "@types/leaflet.markercluster": "^1.5.5", + "open-location-code-typescript": "^1.5.0", "leaflet-contextmenu": "^1.4.0", "leaflet-ant-path": "1.3.0", "leaflet.markercluster": "^1.5.3", diff --git a/src/src/app/shared/latlng-parser.ts b/src/src/app/shared/latlng-parser.ts index 894a285..8ade3a6 100644 --- a/src/src/app/shared/latlng-parser.ts +++ b/src/src/app/shared/latlng-parser.ts @@ -1,3 +1,5 @@ +import OpenLocationCode from "open-location-code-typescript"; + const patternDEC = /^\s*(-?\d{1,3}(?:\.\d+)?)\s*,\s*(-?\d{1,3}(?:\.\d+)?)\s*$/; const patternDD = /^\s*(\d{1,3}(?:\.\d+)?)°?\s*([NS])\s*,\s*(\d{1,3}(?:\.\d+)?)°?\s*([EW])\s*$/i; @@ -33,6 +35,12 @@ export function checkAndParseLatLng( return; } + // Parse PlusCode + if (OpenLocationCode.isValid(value)) { + const result = OpenLocationCode.decode(value); + return [result.latitudeCenter, result.longitudeCenter]; + } + // Parse DMS, DD, DDM to decimal [Lat, Lng] const dec = value.match(patternDEC); if (dec) {