首页 > 解决方案 > 坐标对的迭代问题,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)
    '

标签: pythongoogle-apiiterationcoordinates

解决方案


由于代码不完整且无法运行,我只能猜测您要做什么。但是一旦你有了一个数组/列表,你就可以使用索引或遍历列表来访问列表的元素。

在您的 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)

希望这将帮助您取得一些进展。除此之外,您确实需要发布更完整的代码以及数据文件。理想情况下,您会发布一些我们可以运行的东西,看看会发生什么。在寻求帮助时,存根数据是一种常见的做法。


推荐阅读