From 9e102a3b54f701b96ccb8e505943819715f86420 Mon Sep 17 00:00:00 2001 From: tarunsinghofficial Date: Fri, 5 Jul 2024 20:57:55 +0530 Subject: [PATCH 1/4] added the geolocation featutre that gets the current user location --- src/app.css | 22 ++++++++++++++++ src/components/map/GoogleMap.svelte | 41 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/app.css b/src/app.css index b5c61c9..bf48dc1 100644 --- a/src/app.css +++ b/src/app.css @@ -1,3 +1,25 @@ @tailwind base; @tailwind components; @tailwind utilities; + +.custom-map-control-button { + background-color: #fff; + border: 0; + border-radius: 2px; + box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3); + margin: 10px; + padding: 0 0.3em; + font-size: 25px; + color: #666; + overflow: hidden; + height: 40px; + cursor: pointer; + position: absolute; + bottom: 4em; + right: 0; + z-index: 5; +} +.custom-map-control-button:hover { + background: rgb(235, 235, 235); + color: black; +} diff --git a/src/components/map/GoogleMap.svelte b/src/components/map/GoogleMap.svelte index 126dffd..69ed9c5 100644 --- a/src/components/map/GoogleMap.svelte +++ b/src/components/map/GoogleMap.svelte @@ -44,6 +44,43 @@ if (browser) { window.addEventListener('themeChange', handleThemeChange); } + + const locationButton = document.createElement('button'); + + locationButton.innerHTML = ''; + locationButton.classList.add('custom-map-control-button'); + document.getElementById('map').appendChild(locationButton); + + locationButton.addEventListener('click', () => { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition( + (position) => { + const { latitude, longitude } = position.coords; + const userLocation = new google.maps.LatLng(latitude, longitude); + map.setCenter(userLocation); + + new google.maps.Marker({ + map: map, + position: userLocation, + title: 'Your Location', + icon: { + path: google.maps.SymbolPath.CIRCLE, + scale: 8, + fillColor: '#007BFF', + fillOpacity: 1, + strokeWeight: 2, + strokeColor: '#FFFFFF' + } + }); + }, + () => { + alert('Unable to retrieve your location.'); + } + ); + } else { + alert('Geolocation is not supported by this browser.'); + } + }); } async function loadStopsAndAddMarkers(lat, lng) { @@ -104,6 +141,10 @@ }); +
From af4900e6effe9cfe2736dcf0463d7802ebf1e7da Mon Sep 17 00:00:00 2001 From: tarunsinghofficial Date: Sat, 6 Jul 2024 14:08:56 +0530 Subject: [PATCH 4/4] formatted the app.css for eslint --- src/app.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.css b/src/app.css index bd6213e..b5c61c9 100644 --- a/src/app.css +++ b/src/app.css @@ -1,3 +1,3 @@ @tailwind base; @tailwind components; -@tailwind utilities; \ No newline at end of file +@tailwind utilities;