Using Google Maps API (v3) with Rails (5.2)

Paulo Belo
9 min readSep 22, 2018

Step-by-Step Tutorial

In this tutorial we’ll talk about how to use Google Maps API with Rails. We’ll see some examples of using Static API and Javascript API, how to place a marker and how to update the marker position when we change a form input value. And finally how to update the input value by dragging the marker. All of this without using any gems.

Level: beginner

Pre requisites: basic knowledge of Rails and Javascript

Setup Rails

Please confirm that you have rails >= 5.2 installed (so you can use Rails Credentials)

rails -v

Now let’s create a rails App:

rails new gmaps-rails-example
cd gmaps-rails-example

Let’s continue by creating a basic CRUD App, scaffolding ´Place´:

rails g scaffold Place name:string latitude:decimal longitude:decimal --javascript-engine=js

We have created a Model that holds basic information (name and location) about places, with these fields and types:

  • name: string
  • latitude: decimal
  • longitude: decimal

--

--

Paulo Belo

Developer. Freelancer. Looking for the right words, mainly in ruby and dart.