【问题标题】:Python - guess longitude and latitude based off dynamic addressesPython - 根据动态地址猜测经度和纬度
【发布时间】:2020-04-29 13:50:26
【问题描述】:

我编写了一个程序,它使用 geopy 来查找地址的经纬度。这在 50% 的时间里有效,但似乎只有在地址完美时才有效。

例如地址 'Nedumpana', 'Kollam', 'Kerala', 'India' 给出了 long 和 lat,但地址 'Manakala', 'Pathanamthitta', 'Kerala', 'India' 不会返回结果。显然这是由于地址没有完整填写,但如果我将此地址输入谷歌,那么地址将自动完成以找到正确的经度和纬度。

我的代码如下:

import pyodbc
from  geopy.geocoders import Nominatim
cursor = 'SQL Query'

locator = Nominatim(user_agent='myGeocoder')
for row in cursor:
    if cursor is None:
        break
    else:
        address = list(i for i in row if i)
        location = locator.geocode(','.join(filter(None,address[1:4])))
        if location:
            print(str(address) + '\n Latitude = {}, Longitude = {}'.format(location.latitude, location.longitude))
        else:
            print('Could not find coordinates for ' + str(address))

怎样才能让我的程序在地址不全的地方还能找到这些经纬度地址呢?

非常感谢任何指导!

【问题讨论】:

  • Nominatim 可能不是此类任务的最佳选择。我建议查看其他地理编码器,例如 Photon、Google 或 Here。

标签: python python-3.x geopy


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-21
    • 2011-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    相关资源
    最近更新 更多