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

27/01/2023
geocoding 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: https://github.com/corsego/106-gem-geocoder/commit/ca4485399e9b7d12e1ffde807eec3970eb314068
Text walkthrough: https://blog.corsego.com/gem-geocoder-ruby
Mapbox API: https://docs.mapbox.com/playground/static/

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

1
Join the conversation
Sign in to access PRO lessons, access private repos, leave comments, create watch lists.
We collect your email address, name and username to create your account. We do not share your email address with anyone else.