Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying links in google maps infowindow for multiple markers using Rails 3.1
    primarykey
    data
    text
    <p>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:</p> <pre><code>class CitiesController &lt; ApplicationController ... def businessmap @city = City.find(params[:id]) @mapcenter = @city.geocode @businesses = @city.businesses respond_to do |format| format.html format.json { render :json =&gt; @businesses.to_json(:only =&gt; [:id, :business_name, :phone, :latitude, :longitude]) } end end end </code></pre> <p>The mapview itself is here:</p> <pre><code>%script{:type =&gt; "text/javascript", :charset =&gt; "utf-8", :src =&gt; "http://maps.googleapis.com/maps/api/js?v=3.6&amp;sensor=false&amp;region=IN"} %script{:type =&gt; "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 + '&lt;br/&gt;' + '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 =&gt; "initialize()" } %div#map_canvas{:style =&gt; "width: 900px; height: 600px;"} </code></pre> <p>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" (defined with to_param).</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload