I am trying to add a google map to my application following the code present on this page. http://iheartmyyogi.com/map.html here is the script I have, I made some changes for it to fit my needs... <script type="text/javascript"> var infowindow = null; $(document).ready(function () { initialize(); }); function initialize() { var centerMap = new google.maps.LatLng(29.606880689139555, 69.53661557617194); var myOptions = { zoom: 5, center: centerMap, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); setMarkers(map, sites); infowindow = new google.maps.InfoWindow({ content: "loading..." }); } var sites = [ [''Mount Evans'', 39.58108, -105.63535, 4, ''This is Mount Evans.''], [''Irving Homestead'', 40.315939, -105.440630, 2, ''This is the Irving Homestead.''], [''Badlands National Park'', 43.785890, -101.90175, 1, ''This is Badlands National Park''], [''Flatirons in the Spring'', 39.99948, -105.28370, 3, ''These are the Flatirons in the spring.''] ]; function setMarkers(map, markers) { for (var i = 0; i < markers.length; i++) { var sites = markers[i]; var siteLatLng = new google.maps.LatLng(sites[1]); var marker = new google.maps.Marker({ position: siteLatLng, map: map, title: sites[0], zIndex: sites[2], }); var contentString = "Some content"; google.maps.event.addListener(marker, "click", function () { infowindow.setContent(this.html); infowindow.open(map, this); }); } } </script> In my table I have the following data :Name, :ll_value, :id, I am wondering how I can use ruby to return an array simillar to what the original author is using in var sites? I also tried returning json but the json returned is all html escaped so i am not sure how i can use that in the javascript. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You can make a ajax json request via jquery(what I assume you are using) by using $.getJSON(...). If you want it to just load it in your views use: var sites = <%= site_information.to_json %> where site_information is a hash, or array. You would be best, IMHO, using a hash and rewriting the JS to be a bit more intelligent when adding the markers. On May 19, 10:54 am, QAS WM <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am trying to add a google map to my application following the code > present on this page. > > http://iheartmyyogi.com/map.html > > here is the script I have, I made some changes for it to fit my needs... > > <script type="text/javascript"> > var infowindow = null; > $(document).ready(function () { initialize(); }); > > function initialize() { > var centerMap = new google.maps.LatLng(29.606880689139555, > 69.53661557617194); > var myOptions = { > zoom: 5, > center: centerMap, > mapTypeId: google.maps.MapTypeId.ROADMAP > } > var map = new google.maps.Map(document.getElementById("map_canvas"), > myOptions); > setMarkers(map, sites); > infowindow = new google.maps.InfoWindow({ > content: "loading..." > }); > } > > var sites = [ > [''Mount Evans'', 39.58108, -105.63535, 4, ''This is Mount Evans.''], > [''Irving Homestead'', 40.315939, -105.440630, 2, ''This is the Irving > Homestead.''], > [''Badlands National Park'', 43.785890, -101.90175, 1, ''This is Badlands > National Park''], > [''Flatirons in the Spring'', 39.99948, -105.28370, 3, ''These are the > Flatirons in the spring.''] ]; > > function setMarkers(map, markers) { > for (var i = 0; i < markers.length; i++) { > var sites = markers[i]; > var siteLatLng = new google.maps.LatLng(sites[1]); > var marker = new google.maps.Marker({ > position: siteLatLng, > map: map, > title: sites[0], > zIndex: sites[2], > }); > > var contentString = "Some content"; > google.maps.event.addListener(marker, "click", function () { > infowindow.setContent(this.html); > infowindow.open(map, this); > }); > } > } > </script> > > In my table I have the following data > > :Name, :ll_value, :id, > > I am wondering how I can use ruby to return an array simillar to what > the original author is using in var sites? > > I also tried returning json but the json returned is all html escaped so > i am not sure how i can use that in the javascript. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Just fyi, there is a gem to interact with google maps using Rails3: Gmaps4rails https://github.com/apneadiving/Google-Maps-for-Rails On May 19, 4:54 pm, QAS WM <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am trying to add a google map to my application following the code > present on this page. > > http://iheartmyyogi.com/map.html > > here is the script I have, I made some changes for it to fit my needs... > > <script type="text/javascript"> > var infowindow = null; > $(document).ready(function () { initialize(); }); > > function initialize() { > var centerMap = new google.maps.LatLng(29.606880689139555, > 69.53661557617194); > var myOptions = { > zoom: 5, > center: centerMap, > mapTypeId: google.maps.MapTypeId.ROADMAP > } > var map = new google.maps.Map(document.getElementById("map_canvas"), > myOptions); > setMarkers(map, sites); > infowindow = new google.maps.InfoWindow({ > content: "loading..." > }); > } > > var sites = [ > [''Mount Evans'',39.58108, -105.63535, 4, ''This is Mount Evans.''], > [''Irving Homestead'',40.315939, -105.440630, 2, ''This is the Irving > Homestead.''], > [''Badlands National Park'',43.785890, -101.90175, 1, ''This is Badlands > National Park''], > [''Flatirons in the Spring'',39.99948, -105.28370, 3, ''These are the > Flatirons in the spring.''] ]; > > function setMarkers(map, markers) { > for (var i = 0; i < markers.length; i++) { > var sites = markers[i]; > var siteLatLng = new google.maps.LatLng(sites[1]); > var marker = new google.maps.Marker({ > position: siteLatLng, > map: map, > title: sites[0], > zIndex: sites[2], > }); > > var contentString = "Some content"; > google.maps.event.addListener(marker, "click", function () { > infowindow.setContent(this.html); > infowindow.open(map, this); > }); > } > } > </script> > > In my table I have the following data > > :Name, :ll_value, :id, > > I am wondering how I can use ruby to return an array simillar to what > the original author is using in var sites? > > I also tried returning json but the json returned is all html escaped so > i am not sure how i can use that in the javascript. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
PsiPro wrote in post #999938:> You would be best, IMHO, using a hash and rewriting the JS to be a bit > more intelligent when adding the markers.Unfortunately I am not that good in JavaScript so was trying to match the input with what the script was using. I have modified the controller as such @sites = Array.new $i = 0 for zone in @zones do @sites[$i] = [zone.name, zone.lat, zone.lng, zone.id] $i += 1 end and in my view I am using to to_json method to get the proper json but I have no idea how to modify the script so any help will be greatly appreciated. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
As it turned out, the problem I was having that the variable was returning escaped json and resulting in resulting in errors. Returning raw json did the trick. Thanks for the help guys. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.