Ruby on Rails #106 How to use gem Geocoder, GPS coordinates, distance calculation, map markers

27/01/2023 (about 1 year ago)
geocoding geolocation coordinates longlat encoding address to coordinates coordinates on map

In this episode we will use gem Geocoder to:

  • find for GPS coordinates (latitude and longitude) based on an address;
  • calculate distances in miles and kilometers;
  • search for locations within range (near);
  • search for locations within location (nearbys);
  • use Mapbox API to display a static map

Episode source code:
Text walkthrough:
Mapbox API:

0:00 latitude and longitude coordinates
01:00 geocoder search, calculations
3:25 scaffold Location, seeds
4:40 Geocode existing addresses
6:30 Search Locations NEAR (console)
7:35 Search Locations NEAR (form, controller)
9:35 Configure search NEAR distance
10:31 Search NEARBYS (locations close to current location)
11:55 Distance between locations
12:43 use KILOMETERS, not MILES
14:00 Mapbox Static Maps
17:10 Works! DEMO
17:31 re-geocode if address changed
20:01 Summary

Sign in to join the conversation