Pass list as a string to a function(geocode)

邮差的信 提交于 2020-01-24 00:22:26

问题


I have a def to extract geocodes from gmaps. I can get values individually with the function, though I tried to get a list and convert to string to make it all easier, but it does not work. Any help please?

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

来源:https://stackoverflow.com/questions/56129667/pass-list-as-a-string-to-a-functiongeocode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!