Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9100907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:59:11+00:00 2026-06-17T00:59:11+00:00

I am on ruby and set a map on the page. I can add

  • 0

I am on ruby and set a map on the page. I can add markers upon initialization, but what i would like is to loop through my @events and find the longitude and latitude fields and do something like this

<% @event.each do |event|%>
  <script type="text/javascript">
    var long = <%= event.longitude %>;
    var lati = <%= event.latitude %>;
    addMarker(long, lati);
  </script>
<% end %>

I am not familiar with google api, but was hoping if it was possible.

Here what I have in term of building the map api

function initialize() 
{
    var lat, lon, map, myOptions;
    //check if user has geo feature
    if(navigator.geolocation){
    navigator.geolocation.getCurrentPosition(
    //get position

    function(position){
        lat = position.coords.latitude;
        lon = position.coords.longitude;

        //init map
        myOptions = {
           center: new google.maps.LatLng(lat, lon),
           zoom: 8,
           mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);
            var myLatlng = new google.maps.LatLng(46.4352,-80.9455);
    var marker = new google.maps.Marker({
        position: myLatlng,
        title:"Hello World!"
    });
    // To add the marker to the map, call setMap();
    marker.setMap(map);
    },
    // if there was an error
    function(error){
        alert('ouch');
    });
    }
    //case the users browser doesn't support geolocations
    else 
    {
        alert("Your browser doesn't support geolocations, please consider downloading Google Chrome");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:59:13+00:00Added an answer on June 17, 2026 at 12:59 am

    Here’s my suggestion:

    <script type="text/javascript">
    
      function addMarker(lat, lng) {
        var marker = new google.maps.Marker({
          position: new google.maps.LatLng(lat, lng),
          map: map
        });
      }
    
      <% @events.each do |event| %>
        addMarker(<%= event.latitude %>, <%= event.longitude %>);
      <% end %>
    
    </script>
    

    Create an addMarker function (if it doesn’t already exist) that takes two arguments — latitude and longitude — and adds a corresponding marker to the existing map. Then, you can use Ruby to create one call to addMarker per @event.

    There are ways to optimize this further. For example, you could have a separate Ruby script that outputs the coordinates as JSON, and use asynchronous HTTP request (aka Ajax) to load the coordinates into an array at runtime, which you could then use to populate the map.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With Ruby, how can I set a variable based on a condition? Something like:
I am using Ruby on Rails 3.0.7 and I would like to set a
Using Sinatra in Ruby you can set the server's settings by doing: set :myvariable,
I have just set up ruby in Aptana studio and am getting the following
The default in Ruby on Rails is to have this set to false (in
I am trying to set up a Sinatra based Ruby app to connect to
I've set up a new Rails 2.3.2 app and added the Basecamp API ruby
I'm trying to set up Factory Girl with Test::Unit and Shoulda in Ruby on
In my ruby(1.9.3) on rails (3.1) app I'm trying to set some conditional behavior
Hi I am trying to set up categories on my e-commerce website using Ruby

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.