python - 坐标对的迭代问题,python
问题描述
我很难弄清楚为什么我不能——
1) 遍历从坐标创建的坐标集,
2)在链接弹出时查找整体街道(通常包含 20 个列表)
3) 找出只有“路”字样的确切附近。
请帮忙。
我的最终目标是生成一组坐标,为我提供半径为9000
的附近,在这些附近,我可以找到"road"
和其他关键字。
import requests
import json
APIKEY = "akakak"
import geopandas as gpd
pagetoken = akakakakakak
pagetoken = None
fp = "/Users/akakak/Documents/akakak/akakaka.shp"
data = gpd.read_file(fp)
enugu = data.loc[data['ADM1FIPSNA'] == 'Enugu']
coords=[]
for long, lat in zip(enugu.geometry.y, enugu.geometry.x):
coords.append((long,lat))
def findPlaces(loc = ('x','y'), radius=9000, pagetoken = None):
loc = coords.append((long,lat))
type = "school"
xtype = "vicinity"
xxtype = "road"
url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={lat},{long}&radius={radius}&type={type}&key={APIKEY}{pagetoken}".format(lat = lat, long = long, radius = radius, type = type,APIKEY = APIKEY, pagetoken = "&pagetoken="+pagetoken if pagetoken else "")
print(url)
response = requests.get(url)
res = json.loads(response.text)
print(res)
print("here results ---->>> ", len(res["results"]))
for result in res["results"]:
if xxtype in res["results"]:
if xtype in result["vicinity"]:
info = ";".join(map(str,[result["name"],result["geometry"]["location"]["lat"],result["geometry"]["location"]["lng"],result["types"]]))
print(info)
'
解决方案
由于代码不完整且无法运行,我只能猜测您要做什么。但是一旦你有了一个数组/列表,你就可以使用索引或遍历列表来访问列表的元素。
在您的 def findPlaces() 函数中,更改前几行,如下所示:
def findPlaces(loc, radius=9000, pagetoken = None):
# loc = coords.append((long,lat))
loc = long, lat
type = 'school'
:
在 func 之后,尝试遍历坐标,例如:
for loc in coords:
findPlaces(loc)
希望这将帮助您取得一些进展。除此之外,您确实需要发布更完整的代码以及数据文件。理想情况下,您会发布一些我们可以运行的东西,看看会发生什么。在寻求帮助时,存根数据是一种常见的做法。
推荐阅读
- c - fprintf() 以文本格式写入数据,无论我在 fopen() 中使用何种模式打开文件
- powershell - 使用原始构造函数扩展加速的 .Net 类
- c# - asp.net Identity Roles 组织单元结构创建
- android - 当我回到上一个视图 ViewPager2 时,ExoPlayer 没有播放 onViewRecycled
- javascript - 如何在 ejs 视图中访问 js 变量(在脚本标签内)作为 ejs 变量
- java - 如何在 Android 中避免单例
- php - Razorpay:BAD_REQUEST_ERROR 请提供您的 api 密钥以进行身份验证
- postgresql - 如何在不丢失数据的情况下控制数据库版本,更像是 github
- sql - 如何在 SELECT 查询中间进行调试?
- ios - 如何将图像保存到 ImageView (SwiftUI) 中显示的照片库