【问题标题】:Rails - incorrect google static map - lat long correct for given address -Active Admin - image_tagRails - 不正确的谷歌静态地图 - 给定地址的经纬度正确 - 活动管理员 - image_tag
【发布时间】:2015-05-24 03:57:12
【问题描述】:

ActiveAdmin Rails 4 Google 静态地图问题 下面的代码显示了给定地址的正确经纬度,但在 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

【问题讨论】:

    标签: ruby-on-rails google-maps activeadmin google-static-maps


    【解决方案1】:

    最终将其添加为部分

    更改了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}"
    %>

    【讨论】:

      猜你喜欢
      • 2015-02-15
      • 2012-03-03
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 2017-04-24
      • 2014-10-11
      • 1970-01-01
      相关资源
      最近更新 更多