Skip to content

Instantly share code, notes, and snippets.

@NouranMahmoud
Last active August 29, 2015 14:08
Show Gist options
  • Save NouranMahmoud/e753c85f2320206e94f4 to your computer and use it in GitHub Desktop.
Save NouranMahmoud/e753c85f2320206e94f4 to your computer and use it in GitHub Desktop.
// In controller
@map_markers = []
@estates.each do |key,value|
marker = {location: key.location, estates: value.collect(&:id),property: key.name}
@map_markers << marker
end
// In the view
<%= hidden_field_tag :coordiates,"",id: "coordinates", data: { markers: @map_markers, boundaries: @location } %>
// Javascript file (map initializer)
// getting markers coordinates from the hidden field
var markers = $("#coordinates").data('markers');
for (i = 0; i < markers.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(markers[i]['location']['lat'], markers[i]['location']['lng']),
map: map,
icon: 'http://maps.google.com/mapfiles/kml/pal3/icon56.png',//'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=home|FF0000',
label: '<i class="map-icon-real-estate-agency"></i>',
animation: google.maps.Animation.DROP,
title: markers[i]['property']+" ("+markers[i]['estates'].length+") Estates"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment