From d25883ead415ac9d35a83a87b3136c008af98151 Mon Sep 17 00:00:00 2001 From: Ovidiu U Date: Sat, 11 Apr 2026 21:27:11 +0100 Subject: [PATCH] feat: add geolocation support with Near Me button and user location marker on map - Add "Near Me" button to SearchBar with loading state and geolocation via postcodes.io API - Display user location on map with pulsing blue marker using geolocation API with IP fallback - Adjust map zoom level based on search radius for better context - Pass radiusMiles prop from --- resources/js/components/LeafletMap.vue | 326 ++++++++++++++++--------- resources/js/components/SearchBar.vue | 41 +++- resources/js/views/Home.vue | 4 +- 3 files changed, 254 insertions(+), 117 deletions(-) diff --git a/resources/js/components/LeafletMap.vue b/resources/js/components/LeafletMap.vue index 9b2b69a..6e7abcb 100644 --- a/resources/js/components/LeafletMap.vue +++ b/resources/js/components/LeafletMap.vue @@ -1,81 +1,82 @@ + + diff --git a/resources/js/components/SearchBar.vue b/resources/js/components/SearchBar.vue index d518040..99992bd 100644 --- a/resources/js/components/SearchBar.vue +++ b/resources/js/components/SearchBar.vue @@ -4,17 +4,24 @@
- +
@@ -75,6 +82,28 @@ const postcode = ref('') const fuelType = ref('e10') const radius = ref(10) const sort = ref('price') +const locating = ref(false) + +function useMyLocation() { + if (!navigator.geolocation) return + locating.value = true + navigator.geolocation.getCurrentPosition( + async ({ coords }) => { + try { + const res = await fetch(`https://api.postcodes.io/postcodes?lon=${coords.longitude}&lat=${coords.latitude}&limit=1`) + const json = await res.json() + if (json.result?.[0]?.postcode) { + postcode.value = json.result[0].postcode + onSearch() + } + } finally { + locating.value = false + } + }, + () => { locating.value = false }, + { timeout: 8000, enableHighAccuracy: false, maximumAge: 30000 }, + ) +} function onSearch() { if (!postcode.value.trim()) return diff --git a/resources/js/views/Home.vue b/resources/js/views/Home.vue index 4102c62..8607b5c 100644 --- a/resources/js/views/Home.vue +++ b/resources/js/views/Home.vue @@ -118,7 +118,7 @@ No stations found near you. Try a different postcode or increase the radius.
@@ -423,10 +423,12 @@ const { stations, loading, error, search } = useStations() const sort = ref('price') const lastParams = ref(null) const searchAttempted = ref(false) +const radiusMiles = ref(10) async function onSearch(params) { lastParams.value = params sort.value = params.sort ?? sort.value + radiusMiles.value = params.radius ?? radiusMiles.value searchAttempted.value = true await search(params) }