GoogleマップAPI v3を使用している企業のマーカーが複数あるマップがあります。 infowindowから私のアプリケーションの会社のショービューにリンクする必要があるので、マーカーをクリックするとinfowindowが開き、いくつかの基本情報とリンクが表示され、会社の詳細が表示されます。コードはこれです:Googleマップにリンクを表示するRails 3.1を使用して複数のマーカーを表示するinfowindow
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
のMapView自体はここにある:だから
%script{:type => "text/javascript", :charset => "utf-8", :src => "http://maps.googleapis.com/maps/api/js?v=3.6&sensor=false®ion=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;"}
、今だけの名前と電話番号があり、どのように私は、追加のリンクを表示する(または名前を作ることができますビジネスのリンクがリンクとして表示されます)。リンク自体は、例えば、 "http:// localhost:3000/businesses/186-Cityname-businessname"(to_paramで定義)。
ありがとうございました!
非常に明確で正しい答えを行うコールド方法です。どうもありがとう!! – user929062