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 7011439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:07:39+00:00 2026-05-27T22:07:39+00:00

I have a map with multiple markers of companies using google maps API v3.

  • 0

I have a map with multiple markers of companies using google maps API v3. I need to link from the infowindow to the company show view of my application, so if I click on the marker an infowindow opens with some basic information and a link to view the details of the company. The code is this:

class CitiesController < ApplicationController

...

def businessmap
    @city = City.find(params[:id])
    @mapcenter = @city.geocode
    @businesses = @city.businesses
    respond_to do |format|
      format.html
      format.json { render :json => @businesses.to_json(:only => [:id, :business_name, :phone, :latitude, :longitude]) }
    end
  end
end

The mapview itself is here:

%script{:type => "text/javascript", :charset => "utf-8", :src => "http://maps.googleapis.com/maps/api/js?v=3.6&sensor=false&region=IN"}
%script{:type => "text/javascript"}
  function initialize() {

  var cityLatlng = new google.maps.LatLng(
  = @mapcenter[0]
  ,
  = @mapcenter[1]
  );

  var options = {
  zoom: 13,
  center: cityLatlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  var map = new google.maps.Map(document.getElementById("map_canvas"), options);

  $.getJSON('businessmap.json', function(businesses) {
  $(businesses).each(function() {
  var business = this;
  var infowindow = new google.maps.InfoWindow({
  content: business.business_name + '<br/>' + 'Phone: ' + business.phone
  });
  var marker = new google.maps.Marker({
  position: new google.maps.LatLng(business.latitude, business.longitude),
  map: map,
  icon: image
  });
  google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
  });
  });
  });
  }

%body{ :onload => "initialize()" }
  %div#map_canvas{:style => "width: 900px; height: 600px;"}

So, now there is just the name and the phone number, how can I display an additional link (or make the name of the business appear as a link)? The link itself is e.g. “http://localhost:3000/businesses/186-Cityname-businessname&#8221; (defined with to_param).

Thank you!

  • 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-05-27T22:07:39+00:00Added an answer on May 27, 2026 at 10:07 pm

    The relavent code you’re looking to modify is is the snippet below, where content is getting assigned to whatever will show up in the infowindow when it’s clicked on.

    var infowindow = new google.maps.InfoWindow({
      content: business.business_name + '<br/>' + 'Phone: ' + business.phone
    });
    

    The trick is going to be building the URL, since the JavaScript has no knowledge of Rails routes. You could change the controller’s JSON rendering to include the URL perhaps adding :methods => [:to_param] (the better way) OR build a compatible URL in javascript (the easy way) and hoping that whatever parses the URLs only uses the integers.


    Easy Way

    In the view –

    var infowindow = new google.maps.InfoWindow({
      content: '<a href="/businesses/' + business.id + '">' + business.business_name + '</a><br/>' + 'Phone: ' + business.phone
    });
    

    Slightly Better Way

    In the controller –

    format.json { render :json => @businesses.to_json(:only => [:id, :business_name, :phone, :latitude, :longitude], :methods => [:to_param]) }
    

    In the view –

    var infowindow = new google.maps.InfoWindow({
      content: '<a href="/businesses/' + business.to_param + '">' + business.business_name + '</a><br/>' + 'Phone: ' + business.phone
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found a code to show Google maps with multiple markers using JQuery
Hi I have this weird problem with Google Maps V3 API. Showing multiple markers
i have a google map with multiple markers and each has its own infowindow.
I understand that if I have multiple markers on a map, and I need
I need to display multiple markers on a map, each with their own infowindow.
I currently have a Google map that geocodes multiple markers on the fly but
I'm trying to add infoWindow's to multiple markers on a Google Map. The closest
I'm using Google Maps API on my web page. I'm try to add multiple
I have successfully implemented code to plot multiple locations on google maps dynamically. Solution:
i am using google maps api v3, and the InfoBubbles plugin. I am trying

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.