Getting Time Zone from Lat Long Coordinates?(从经纬度坐标获取时区?)
问题描述
我正在尝试获取纬度和经度坐标的时区,但遇到了一些问题这些错误可能是非常基本的
I am trying to get the time zones for latitude and longitude coordinates but am having a few problems The mistakes are probably very basic
我在数据库中有一个大约 600 行的表.每行包含世界某处的经纬度坐标我想将这些坐标输入一个函数,然后检索时区.目的是将在这 600 个地点中的每个地点具有本地时间戳的事件转换为 UTC 时间
I have a table in a database with around 600 rows. Each row contains a lat long coordinate for somewhere in the world I want to feed these co-ordinates into a function and then retrieve the time zone. The aim being to convert events which have a local time stamp within each of these 600 places into UTC time
我发现了一篇博文使用一段代码从地理坐标导出时区.
I found a blog post which uses a piece of code to derive timezones from geographical coordinates.
当我尝试运行代码时,我收到错误geonames is not defined
.我已经申请了一个带有地名的帐户.
When I try to run the code, I get the error geonames is not defined
. I have applied for an account with geonames.
我想我只是将函数文件保存在错误的目录中或一些简单的东西.谁能帮忙
I think I have just saved the function file in the wrong directory or something simple. Can anyone help
#-------------------------------------------------------------------------------
# Converts latitude longitude into a time zone
# REF: https://gist.github.com/pamelafox/2288222
# REF: http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html
#-------------------------------------------------------------------------------
geonames_client = geonames.GeonamesClient('Username_alpha')
geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng': 2.77928})
user.timezone = geonames_result['timezoneId']
推荐答案
这按预期工作:
import geonames
geonames_client = geonames.GeonamesClient('demo')
geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng': 2.77928})
print geonames_result['timezoneId']
输出:
'Europe/Paris'
这篇关于从经纬度坐标获取时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从经纬度坐标获取时区?
基础教程推荐
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01