Free Ruby on Rails #108 How to use the Browser Geolocation API with Rails

02/02/2023 (over 1 year ago)
browser api stimulusjs javascript geolocation api find nearby

Another geolocation episode!
In previous episodes we learnt to get COORDINATES based on address, and place coordinates on a map.
Now, we will learn to get a users' accurate geolocation based on browser Geolocation API. It is supported by any browser!
We will integrate Geolocation into a Rails app with StimulusJS.

Warning! Asking for access to the location on page load will result in most of your users rejecting access.

Blogpost for this video:
Episode source code:

P.S. what do you think about my new setup 🌜? That's actually the reason I did the few previous episodes without showing face 🌝

0:00 Geocoding and maps recap
0:35 Example search by current location
1:08 Browser Geolocation API
1:40 Stimulus Geolocation Controller
4:04 Button to get location
5:10 Search near me (use browser coordinates in query)
6:40 Works! DEMO
7:18 Geolocation accuracy problems?!

Sign in to join the conversation