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'
这篇关于从经纬度坐标获取时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从经纬度坐标获取时区?


基础教程推荐
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01