Skip to main content

Subscribe to GoRails to get access to this episode and all other pro episodes, and new awesome content every month.

Subscribe Now
Only $19/month

Unlimited access. Cancel anytime.

16 How to use Google Maps and Markers

Episode 204 · August 29, 2017

Using the Gmaps.js library, we can really easily add Google Maps to our Rails applications

Javascript Maps Geocoding


Transcripts

Subscribe or login to view the transcript for this episode.

Discussion


Gravatar
Ryan Steen (80 XP) on

Awesome video. I am wondering how would I take the show page and link it to a different js file. The index.js is global correct? What would be the best way to setup a show view with just the map for a specific item?

Gravatar
Chris Oliver (169,620 XP) on

Hey Ryan,

What you want is to simply define a div with the id of map on the show page and have the markers array be just the item on the page (instead of all the ones on the index). The Javascript is available on every page so you're free to add a map to other pages and it will automatically work!

This is the benefit of writing javascript that's generic to pages. A lot of people want "page-specific" javascript but that's almost always a bad idea. You can always use a unique identifier for your JS to pickup and make your life a lot easier in the long run.

Gravatar
Ryan Steen (80 XP) on

I am having a hard time understanding how page specific js would be bad? What if I would like a different kind of map for a different page or js that would be used only on one specific page? Is there an easy way to implement it when deemed necessary?

Gravatar
Brett McHargue (410 XP) on
I don't think `bad` is the right term here - it's just that page specific js makes it more difficult to share functionality across pages and is usually not required.  But when it is needed we have a `content_for :load_last` at the bottom of our application layout that we use.

Gravatar
Diogo (1,810 XP) on

Hey Chris,

I would love you to cover how to make custom infowindows with custom colors, content, without the "x" button, etc ( a la Airbnb for example ).

Keep it up

Gravatar
Chris Oliver (169,620 XP) on

Probably doing something like these solutions would work: https://stackoverflow.com/q...


Gravatar
Stephen Sizer (730 XP) on

Great Video!!

I would love to use this with a population density overlay.. does anyone know where I can get that data?


Login or create an account to join the conversation.