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) }