【问题标题】:Rails Get timezone from latitude and longitude using TimezoneRails 使用 Timezone 从纬度和经度获取时区
【发布时间】:2012-09-16 17:15:52
【问题描述】:

我正在开发一个 Rails 应用程序,我想从纬度和经度获取 时区。我在 stackoverflow 上搜索了这个,发现这个link 是最好的方法。

我安装了 gem geokittimezone 并尝试在我的控制台中实现相同的功能:

require 'geokit'
require 'timezone'
res = Geokit::Geocoders::GoogleGeocoder.geocode('140 Market St, San Francisco, CA')
timezone = Timezone::Zone.new(:latlon => res.ll)

但我得到了这个错误

ArgumentError: wrong number of arguments (1 for 2)

我查看了Timezone 的文档。 他们要求通过注册获得用户名。但是我还没有收到任何激活邮件。有人可以为此提出一些解决方案吗?

提前致谢。

【问题讨论】:

标签: ruby-on-rails-3 timezone


【解决方案1】:

看起来调用 Timezone::Zone.new(:latlon => res.ll) 不起作用(至少我得到了同样的错误)。我认为这是由于谷歌返回的 res.ll 值的格式发生了变化。但是这个电话应该可以完成这项工作:

Timezone::Zone.new(lat: res.lat, lon: res.lng)

但是,首先请确保您创建一个具有 GeoNames 的帐户并活动here。您还必须为时区 gem 创建和配置初始化程序。后者在此处描述:timezone/lib/timezone/configure.rb

【讨论】:

    猜你喜欢
    • 2014-01-25
    • 1970-01-01
    • 2011-11-12
    • 2021-04-16
    • 2017-02-22
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多