-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add handling of lat, lon coordinate queries (#368)
Quick, *pure js* implementation to handle coordinate queries (#147). If a user enters valid coordinates, they get a single result with that point (as in Google Maps and other services). It's a useful feature for power users. ![image](https://github.com/smeijer/leaflet-geosearch/assets/8945883/775ac7a2-3802-44e8-a3d5-c59d91d579e6) Any other queries are sent to the Provider. Happy to see this in TypeScript and otherwise improved, it's probably not ready for merging. --------- Co-authored-by: Stephan Meijer <[email protected]>
- Loading branch information
1 parent
f321ef5
commit 1f19d1a
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @ts-nocheck | ||
|
||
export function validateCoords(query) { | ||
const q = query.trim(); | ||
const regex = /^(-?[0-9]*\.?\s*[0-9]*)\s*,?\s*(-?[0-9]*\.?[0-9]*)$/g; | ||
const match = regex.exec(q); | ||
if (match) { | ||
const lat = Number(match[1]); | ||
const lng = Number(match[2]); | ||
if (-90 < lat < 90 && -180 < lng < 180) { | ||
return [ | ||
{ | ||
x: lng, | ||
y: lat, | ||
label: q, | ||
bounds: null, | ||
raw: {}, | ||
}, | ||
]; | ||
} | ||
} | ||
return false; | ||
} |