2015-01-17 3 views
1

하나의 정적지도에 여러 개의 표식을 표시하려고합니다.하나의 정적지도에 여러 마커를 사용하는 방법은 무엇입니까?

나는 geocoder gem을 사용 중입니다 (이에 대해서는 railscast tutorial을 따름). 그 일을하기 위해 관리.

이제 색인 페이지의 모든지도를 하나의지도에 반복하려고하는데 각지도마다 별도로 표시됩니다.

<% @locations.each do |location| %> 
<%= image_tag "http://maps.google.com/maps/api/staticmap?size=450x300&sensor=false&zoom=15&markers=#{location.latitude}%2C#{location.longitude}" %> 
<% end %> 

어떻게이 통해 루프 때문에 모든 마커는 각각의 모든 하나의 경도 값/위도 하나지도 대신 맵에 표시 할 :

이 인덱스 페이지의 코드는?

조언을 제공해 주시면 추가 정보를 알려 주시기 바랍니다.

답변

4

각 마커의 이미지를 인쇄하기 때문에 각지도가 별도로 표시됩니다. 원하는 것은 하나의 URL이고 각 마커의 끝에는 &markers=#{location.latitude}%2C#{location.longitude}을 추가하십시오.

그래서 코드는 다음과 같아야합니다

<% my_url = "http://maps.google.com/maps/api/staticmap?size=450x300&sensor=false&zoom=15" %> 
<% @locations.each do |location| %> 
<% my_url += "&markers=#{location.latitude}%2C#{location.longitude}" %>  
<% end %> 
<%= image_tag my_url %> 
+0

P 이봐, 고마워! 방금 당신의 대답을보고 그것을 바로 시도했습니다. 처음에는 문제가 있었지만 원래 항목을 모두 삭제 한 후에 작동했습니다. 그들은 전세계에 흩어져있었습니다. 한 대륙에있을 때 더 잘 작동합니다. 한숨. – user273072545345

0

마테이의 대답은 정확하지만 도우미에서이를 호출하면 좋을 것이다. 이 같은 것이 아마도

def nice_gmap_static(location) 
    center = "#{location.latitude},#{location.longitude}" 
    "https://maps.googleapis.com/maps/api/staticmap?center=#{center}&size=300x300&zoom=17&markers=#{location.latitude}%2C#{location.longitude}" 
    end