将列表作为字符串传递给函数(地理编码)

时间:2019-05-14 11:44:15

标签: string list function geocode

我有一个def可以从gmap中提取地理编码。尽管可以尝试获取列表并将其转换为字符串以使其变得更容易,但是我可以使用该函数单独获取值,但是它不起作用。 有什么帮助吗?

gmaps_key = googlemaps.Client(key=API_KEY)
gm = googlemaps.Client(key=API_KEY)


 def Geocode(*query):
    #if isinstance(query, str):
     #   query = [query]
        #query = data.index.values.tolist()
        query = str(query)
        #query = query.next()
        #query = query.split()
        try:
            geocode_result = gm.geocode(query)[0]       
            latitude = geocode_result['geometry']['location']['lat']
            longitude = geocode_result['geometry']['location']['lng']
            bounding_box = geocode_result['geometry']['viewport']
            lat_boundaryS = [bounding_box['southwest']['lat']]
            lat_boundaryN = [bounding_box['northeast']['lat']]
            lng_boundaryS = [bounding_box['southwest']['lng']]
            lng_boundaryN = [bounding_box['northeast']['lng']]

            return {    'name':query,
                        'lat':latitude,
                        'lng':longitude,
                        'southwest': [lat_boundaryS, lat_boundaryN],
                        'northeast': [lng_boundaryS, lng_boundaryN]}
        except IndexError:
            return 0

0 个答案:

没有答案