python - 使用 Python 进行地理编码 - 仅从公司名称中获取地址
问题描述
我目前正在从事一个项目,其中我有一个公司名称列表,我必须获得每个公司的地址。我已经尝试过对 google API 甚至以下代码进行地理编码,但它不起作用。
> from geopy.geocoders import Nominatim
> geolocator = Nominatim(user_agent="specify_your_app_name_here")
> location = geolocator.geocode("Company name")
> print(location.address)
> print((location.latitude, location.longitude))
> print(location.raw)
有谁知道这是怎么做到的吗?
非常感谢,
解决方案
我在英国伊斯灵顿的安吉尔随机选择了一家名为 Chilango 的快餐店。然后我通过 MapQuest尝试了 Open Search (Nominatim) API 。免费且需要 API 密钥。
我模仿了一个示例 GET 请求:
import requests
res = requests.get('http://open.mapquestapi.com/nominatim/v1/search.php?key=myKey&format=json&q=Chilango+[fast food]&addressdetails=1&limit=3&viewbox=-1.99%2C52.02%2C0.78%2C50.94&exclude_place_ids=41697').json()
从文档中:
将查询字符串括在 [] 中会导致 Nominatim 进行设施搜索。例如,q=[pub] 返回 OpenStreetMap 中 type=pub 的结果。
期望的结果是我限制搜索结果的 3 个结果中的第 2 个。
推荐阅读
- r - 如何在ggplot中对颜色进行分组?
- mongodb - TypeORM for MongoDB vs mongoosejs
- powershell - 如何将 LastWriteTime 添加到此脚本?
- python - Python 错误 AuthenticationError:(状态 400)(Quandl 错误 QEAx01)我们无法识别您的 API 密钥。请检查您的 API 密钥并重试
- batch-file - CMD:将命令的结果绑定到变量并在下一次调用中使用它
- html - 单击菜单项后关闭 Bootstrap 4 可悬停下拉菜单
- r - 如何强制 r-mapview 在弹出窗口或某些行上显示所有数据,而不考虑 zcol=
- python - RADIUS 计算 Message-Authenticator 字段(python)
- ios - 如何将 IBOutlet 值从视图传递到 VIPER iOs 中的交互器?
- ios - 在 Swift 4 上调整 UIImage 视图的大小