在我的 Rails 应用程序中,地图标记加载得非常好,但我无法让地图以加拿大 AB 的卡尔加里市为中心。我正在使用用户的位置(按 IP 进行地理编码),而且我似乎无法在地图上显示一个红色圆圈(描绘范围)。
我的控制器中有以下内容:
if !request.xhr?
@json = @students.to_gmaps4rails do |student, marker|
marker.infowindow render_to_string(:partial => "/map/infowindow", :locals => {:student => student})
marker.title "#{student.name}, Grade: #{student.grade}"
marker.json({:name => student.name, :address => student.full_address, :grade => student.grade, :subjects => student.subjects})
end
@mapOptions = "[{ 'map_options' => { 'type' => 'SATELLITE', 'detect_location' => true, 'center_on_user' => true, 'center_latitude' => 50, 'center_longitude' => -114, 'auto_adjust' => true} }]"
end
@circles = "[{'lng': '#{results['address']['lng']}', 'lat': '#{results['address']['lat']}', 'radius': '#{(results['radius'] * 1000)}', 'strokeColor': '#{ '#FF0000'}'}]"
.
.
.
respond_to do |format|
format.html
format.xml {render :xml => [@subjects,@students,@address].to_xml}
format.json {render :json => [@subjects,@students,@address].to_json}
end
索引.haml:
= gmaps({"map_options" => {"data" => @mapOptions}, "markers" => {"data" => @json}, "circles" => {"data" => @circles} })
现在,最终,我希望能够通过使用 ajax 请求来更改地址。