使用纬度和经度转换为本地时区? [英] convert to local time zone using latitude and longitude?
本文介绍了使用纬度和经度转换为本地时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含以下信息的数据集:纬度、经度、EST 时间.例如,对于一个观察
I have a data set with the following information: latitude, longitude, EST time. For example, for one observation
lat = 13
long = -2
time1 = as.POSIXlt("2014-02-12 17:00:00", tz = "EST")
我想创建一个新的变量 timeL,即本地时间.有关如何使用 R 执行此操作的任何建议?
I want to create a new variable timeL that is the local time. Any suggestions of how to do this with R?
谢谢!
推荐答案
lat = 13
long = -2
time1 <- as.POSIXct("2014-02-12 17:00:00", tz = "EST")
# https://developers.google.com/maps/documentation/timezone/
apiurl <- sprintf("https://maps.googleapis.com/maps/api/timezone/%s?location=%s,%s×tamp=%d&sensor=%s",
"xml",
lat,
long,
as.numeric(time1),
"false")
library(XML)
tz <- xmlParse(readLines(apiurl))[["string(//time_zone_id)"]]
as.POSIXct(format(time1, tz=tz))
# [1] "2014-02-12 22:00:00 CET"
或者,按照@SymbolixAU 的建议,使用他们的 googleway
包:
or, as suggested by @SymbolixAU, use their googleway
package:
res <- googleway::google_timezone(c(lat, long), time1, key = NULL)
as.POSIXct(format(time1, tz=res$timeZoneId))
# [1] "2014-02-12 22:00:00 CET"
这篇关于使用纬度和经度转换为本地时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文