Give feedback on:
In order to embed a Google Map onto your site, you have to use some Javascript. The Javascript code will work alongside your Rails code to display data from your Rails app.
So, before we jump into Google Maps, let's review some Javascript.
> var x = "Hello";
undefined
> x
"Hello"
> function shout(msg) { alert(msg); }
undefined
> shout('Hey');
// a browser popup alert is shown
> console.log('hey');
hey
undefined
> function get(url, data, onSuccess) { onSuccess(); }
undefined
> get('www.place.com', {"q": "test"}, function() { alert('hey'); });
// popup alert with 'hey' is shown
Since Javascript is primarily used in browsers, most of the usage is geared toward modifying content in web pages. This usually means hiding/showing elements on the page, animating elements, or loading new content into the page via a Javascript request.
The Document Object Model is a tree of all of your HTML elements. Think of it as a tree mapping of your entire HTML document.
<html>
<head>
<title></title>
</head>
<body>
<div class="parent">
<p class="children">
<a href="/" class="grandchild"></a>
</p>
<p class="children"></p>
</div>
</body>
html
|-head
|- title
|-body
|-div.parent
|-p.children
|- a.grandchild
|-p.children
$('#projects'); // selects all elements with id='projects'
$('.item'); // selects all elements with class='item'
$('#projects').html('No projects found.'); // replaces the inner HTML
$('#message').show('fast'); // animates showing element
$('#menu').slideDown(); // animates down the element
Let's integrate a Google Maps view into our Twitter app to show a world view of all the locations of tweets.
We can try this gem: https://github.com/apneadiving/Google-Maps-for-Rails