Skip to content

Commit b7ce1fd

Browse files
authored
Merge pull request #119 from GoBuildOrg/dev2
added location support
2 parents c77f486 + dc321de commit b7ce1fd

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

src/components/HeroForm.tsx

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ const handleLocationSelect = (value: string) => {
7474
}
7575
};
7676

77+
const handleUseCurrentLocation = () => {
78+
if (!navigator.geolocation) {
79+
toast({ title: 'Error', description: 'Geolocation is not supported by your browser', variant: 'destructive' });
80+
return;
81+
}
82+
83+
navigator.geolocation.getCurrentPosition(
84+
(pos) => {
85+
const { latitude, longitude } = pos.coords;
86+
setMapCenter({ lat: latitude, lng: longitude });
87+
setLocation(`lat:${latitude.toFixed(5)} , lon:${longitude.toFixed(5)}`);
88+
setShowSuggestions(false);
89+
},
90+
(err) => {
91+
toast({ title: 'Error', description: err.message || 'Unable to retrieve your location', variant: 'destructive' });
92+
},
93+
{ enableHighAccuracy: true }
94+
);
95+
};
96+
7797

7898
const filteredLocations = locationList.filter((loc) =>
7999
loc.toLowerCase().includes(location.toLowerCase())
@@ -190,19 +210,31 @@ return(
190210
</div> */}
191211
</div>
192212

193-
{/* LOCATION AUTOCOMPLETE */}
194213
<div className="space-y-2 relative">
195214
<label className="text-sm font-medium text-sky-900">Location</label>
196215

197-
<Input
198-
placeholder="Enter location"
199-
className="bg-white"
200-
value={location}
201-
onChange={(e) => {
202-
setLocation(e.target.value);
203-
setShowSuggestions(true);
204-
}}
205-
/>
216+
<div className="flex gap-2 items-center">
217+
<span className="relative flex items-center justify-center w-14 h-9 rounded-full bg-gradient-to-tr from-emerald-400 to-sky-500 shadow-md">
218+
<MapPin className="w-4 h-4 text-white" />
219+
<span className="absolute inline-flex w-9 h-9 rounded-full bg-emerald-300 opacity-30 animate-ping" />
220+
</span>
221+
<Button
222+
variant="outline"
223+
className="whitespace-nowrap flex items-center gap-3"
224+
onClick={handleUseCurrentLocation}
225+
>
226+
<span className="font-normal">Current location</span>
227+
</Button>
228+
<Input
229+
placeholder="Enter location"
230+
className="bg-white"
231+
value={location}
232+
onChange={(e) => {
233+
setLocation(e.target.value);
234+
setShowSuggestions(true);
235+
}}
236+
/>
237+
</div>
206238

207239
{showSuggestions && location && filteredLocations.length > 0 && (
208240
<div className="absolute left-0 right-0 top-full mt-1 border rounded-md bg-white max-h-60 overflow-auto shadow-lg z-50">

0 commit comments

Comments
 (0)