Геокодер не будет возвращать координаты для экземпляра класса - PullRequest
1 голос
/ 28 мая 2019

Я пытаюсь использовать гем геокодера, чтобы применить координаты широты и долготы к моей модели CoffeeShops, но я не могу заставить геокодер вернуть координаты.

Когда я пытаюсь сохранить новый экземпляр класса с адресом, он успешно сохраняется в базе данных, но информация о геокодировании для долготы и широты равна 'nil'.

Я пробовал установить пакет. Я попытался добавить тайм-аут в инициализаторе geocoder.rb Я попытался добавить и удалить проверку адреса (наличие: true) в модели

Модель моей кофейни:

class CoffeeShop < ApplicationRecord
  belongs_to :user
  has_many :reviews
  has_one :feature_set
  has_one :wifi_speed, through: :feature_sets

  validates :name, :address, presence: true
  geocoded_by :address
  after_validation :geocode, if: :will_save_change_to_address?
end

Файл переноса моего адреса:

class AddAddressToCoffeeShops < ActiveRecord::Migration[5.2]
  def change
    add_column :coffee_shops, :address, :string
  end
end

Файл миграции моих координат:

class AddCoordiantesToCoffeeShops < ActiveRecord::Migration[5.2]
  def change
    add_column :coffee_shops, :latitude, :float
    add_column :coffee_shops, :longitude, :float
  end
end

Схема моей кофейни:

create_table "coffee_shops", force: :cascade do |t|
    t.string "name"
    t.string "description"
    t.integer "rating"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.bigint "user_id"
    t.float "latitude"
    t.float "longitude"
    t.string "address"
    t.index ["user_id"], name: "index_coffee_shops_on_user_id"
  end

Мой инициализатор геокодера

Geocoder.configure(
  # Geocoding options
  # timeout: 3,                 # geocoding service timeout (secs)
  # lookup: :nominatim,         # name of geocoding service (symbol)
  # ip_lookup: :ipinfo_io,      # name of IP address geocoding service (symbol)
  # language: :en,              # ISO-639 language code
  # use_https: false,           # use HTTPS for lookup requests? (if supported)
  # http_proxy: nil,            # HTTP proxy server (user:pass@host:port)
  # https_proxy: nil,           # HTTPS proxy server (user:pass@host:port)
  # api_key: nil,               # API key for geocoding service
  # cache: nil,                 # cache object (must respond to #[], #[]=, and #del)
  # cache_prefix: 'geocoder:',  # prefix (string) to use for all cache keys

  # Exceptions that should not be rescued by default
  # (if you want to implement custom error handling);
  # supports SocketError and Timeout::Error
  # always_raise: [],

  # Calculation options
  units: :km,                 # :km for kilometers or :mi for miles
  # distances: :linear          # :spherical or :linear
)
...