android获取经纬度blh,如何通过earthtools.org从经纬度获得TimeZone

这段代码展示了如何使用TimeZoneFinder库来获取经纬度对应的时区偏移量和时区ID,并利用这些信息设置Ruby的时区,以便进行时间操作。示例中,通过HTTP请求获取指定地理位置的时区信息,然后解析XML响应以提取关键数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# offset = TimeZoneFinder.gmt_offset(some_lat, some_lng)

# timezone = ActiveSupport::TimeZone[offset]

#

# timezone = TimeZoneFinder.timezoneId(lat, lng)

# Time.zone = timezone

# Time.zone.now

#

class TimeZoneFinder

attr_accessor :result

def self.gmt_offset(lat,lng)

self.new(lat,lng).find('gmtOffset').to_f

end

def self.timezoneId(lat,lng)

self.new(lat,lng).find('timezoneId')

end

def initialize(lat,lng)

uri = URI.parse("http://ws.geonames.org/timezone?lat=#{lat}&lng=#{lng}")

@result = Hash.from_xml(open(uri))

end

def find(key)

result["geonames"]["timezone"][key]

end

end

# Example XML response...

#

#

# US

# United States

# 41.8781136

# -87.6297982

# America/Chicago

# -5.0

# -6.0

# -6.0

# 2011-09-01 21:40

# 2011-09-02 06:16

# 2011-09-02 19:22

#

# `enter code here`

2012-10-10 05:06:33

akaco

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值