Markers are a very useful feature of Google Maps. They allow you to display the location of an item in a search result, for example. This demo shows how simple it is to put markers on a map with Google4R.

The following fragment of code creates a new GMap2 widget and then puts ten markers at random positions around the Google headquarters. If the user clicks on a marker then a information bubble with some HTML text will open.

1
2
3
4
5
6
7
8
9
10
11
map = Google4R::Maps::GMap2.new("map", "map-div")

point = [ 37.4419, -122.1419 ]

1.upto(10) do |i|
  marker = map.create_marker([ point[0] + (rand - 0.5), point[1] + (rand - 0.5)])
  marker.title = "marker no. #{i}"
  marker.info_window_html = "Some <em>HTML</em> text for a pop up window."
end

map.to_html

See the result.