mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-21 06:11:45 +00:00
feat: import places from Google Maps URLs — closes #141
Paste a Google Maps URL into the place search bar to automatically import name, coordinates, and address. No API key required. Supported URL formats: - Short URLs: maps.app.goo.gl/..., goo.gl/maps/... - Full URLs: google.com/maps/place/.../@lat,lng - Data params: !3dlat!4dlng embedded coordinates Server resolves short URL redirects and extracts coordinates. Reverse geocoding via Nominatim provides name and address.
This commit is contained in:
@@ -104,6 +104,24 @@ export default function PlaceFormModal({
|
||||
if (!mapsSearch.trim()) return
|
||||
setIsSearchingMaps(true)
|
||||
try {
|
||||
// Detect Google Maps URLs and resolve them directly
|
||||
const trimmed = mapsSearch.trim()
|
||||
if (trimmed.match(/^https?:\/\/(www\.)?(google\.[a-z.]+\/maps|maps\.google\.[a-z.]+|maps\.app\.goo\.gl|goo\.gl)/i)) {
|
||||
const resolved = await mapsApi.resolveUrl(trimmed)
|
||||
if (resolved.lat && resolved.lng) {
|
||||
setForm(prev => ({
|
||||
...prev,
|
||||
name: resolved.name || prev.name,
|
||||
address: resolved.address || prev.address,
|
||||
lat: String(resolved.lat),
|
||||
lng: String(resolved.lng),
|
||||
}))
|
||||
setMapsResults([])
|
||||
setMapsSearch('')
|
||||
toast.success(t('places.urlResolved'))
|
||||
return
|
||||
}
|
||||
}
|
||||
const result = await mapsApi.search(mapsSearch, language)
|
||||
setMapsResults(result.places || [])
|
||||
} catch (err: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user