2012-10-16 50 views
0

我有一個應用程序,用於展示商家信息,然後顯示與該商家相關的各種工作。工作地點工作很好,但我想爲應該在中心的業務添加一個標記,然後我可以自定義該標記。使用gmaps4rails將標記添加到中心位置

這裏是我的控制器/ business_controller

def show 
    @business = Business.find(params[:id]) 
    @distance = @business.service_area 
    @jobs = Job.near(@business.location, @distance, {:order => :distance, :units => :km}) 
    @json = @jobs.to_gmaps4rails 
    @mapoptions = { 
     "map_options" => {"center_latitude" => @business.latitude, 
         "center_longitude" => @business.longitude, 
         "auto_zoom" => true} 
       } 
    respond_to do |format| 
    format.html 
    end 
end 

在我看來看法/企業/顯示

<p><%= gmaps(:map_options => @mapoptions,"markers" => { "data" => @json }) %></p> 

如何創建爲企業位置的標記?

回答

0

我會說:

markers_array = JSON.parse @jobs.to_gmaps4rails 
markers_array << {lat: @business.latitude, lng: @business.longitude} 
@json = markers_array.to_json 
+0

感謝您的幫助。 –

相關問題