Rails - 不正确 google 静态地图 - 给定地址的经纬度正确 - 活动管理员 - image_tag

Rails - incorrect google static map - lat long correct for given address -Active Admin - image_tag

A​​ctiveAdmin Rails 4 Google 静态地图问题 下面的代码显示了给定地址的正确纬度和经度,但是当在 googlemap 静态地图中使用时,它显示了完全不正确的地图。你能想到什么理由?如果我手动将纬度和经度放入 http: 地图字符串中,则会出现正确的地图。

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/adresses/_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}"
%>