Rails -不正确的谷歌静态地图- lat长正确的给定地址- active Admin - image_tag



ActiveAdmin Rails 4 Google静态地图问题下面的代码显示了正确的lat和long for give地址,但当在googlemap静态地图中使用时,它显示了完全不正确的地图。你能想到什么原因吗?如果我手动将lat和long放入http: map字符串中,就会出现正确的映射。

ActiveAdmin.register Address do
  permit_params :address, :longitude, :latitude
  # See permitted parameters documentation:
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  #
  #
  # or
  #
  # permit_params do
  #   permitted = [:permitted, :attributes]
  #   permitted << :other if resource.something?
  #   permitted
  # end
  index do
    selectable_column
    id_column
    column :address
    actions
  end
  filter :address
  form do |f|
    f.inputs "Address Details" do
      f.inputs :address
    end
    f.actions
    end
  show do
    attributes_table do
      # other rows
      row :address
      row :latitude
      row :longitude
      content do
      render 'googlemap'
      end
      row :addressMap do
    image_tag "https://maps.googleapis.com/maps/api/staticmap?center=#{:latitude},#{:longitude}&zoom=13&size=600x300&maptype=roadmap"
      end
    end
  end
end

最终将其作为部分插件

更改activeadmin地址表单/app/admin/address.rb

  show do
    attributes_table do
      # other rows
      row :address
      row :latitude
      row :longitude
     end
# renders app/views/admin/addresses/_googlemap.html.erb
    render partial: 'googlemap'
    active_admin_comments
  end

和/app/views/admin/addresses/_google.html.erb的部分

<%= image_tag "https://maps.googleapis.com/maps/api/staticmap?center=#{@address.latitude},#{@address.longitude}&zoom=18&size=600x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:red%7Clabel:1%7C#{@address.latitude},#{@address.longitude}"
%>

相关内容

最新更新