Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:如何将*args传递到元组GoogleAPI_Python_Google Maps_Tuples_Args - Fatal编程技术网

Python:如何将*args传递到元组GoogleAPI

Python:如何将*args传递到元组GoogleAPI,python,google-maps,tuples,args,Python,Google Maps,Tuples,Args,目前我正在使用Google API for Python。 我使用google Place库作为google距离矩阵的输入参数。 这就是我所拥有的: Dest = google_places.nearby_search( location='Jakarta, Indonesia', keyword='Kantor, Office, Building', radius=random.randrange(1000,20000)) self. home = random.choice (Org)

目前我正在使用Google API for Python。 我使用google Place库作为google距离矩阵的输入参数。 这就是我所拥有的:

Dest = google_places.nearby_search( 
location='Jakarta, Indonesia',
keyword='Kantor, Office, Building', 
radius=random.randrange(1000,20000))

self. home = random.choice (Org)

self.destination = random.choice(Dest.places)

self.expected = gmaps.distance_matrix(random, self.destination)
我犯了一系列错误

 File "C:/Users/TrafficModel.py", line 52, in __init__
    self.expected = gmaps.distance_matrix(self.home, self.destination)
  File "C:\Python35\lib\site-packages\googlemaps\client.py", line 337, in wrapper
    result = func(*args, **kwargs)
  File "C:\Python35\lib\site-packages\googlemaps\distance_matrix.py", line 90, in distance_matrix
    "destinations": convert.location_list(destinations)
  File "C:\Python35\lib\site-packages\googlemaps\convert.py", line 128, in location_list
    return "|".join([latlng(location) for location in as_list(arg)])
  File "C:\Python35\lib\site-packages\googlemaps\convert.py", line 128, in <listcomp>
    return "|".join([latlng(location) for location in as_list(arg)])
  File "C:\Python35\lib\site-packages\googlemaps\convert.py", line 79, in latlng
    normalized = normalize_lat_lng(arg)
  File "C:\Python35\lib\site-packages\googlemaps\convert.py", line 107, in normalize_lat_lng
    "but got %s" % type(arg).__name__)
TypeError: Expected a lat/lng dict or tuple, but got Place
我认为这就是问题所在

我该怎么处理这个?谢谢

您可以使用

dest = self.destination
self.expected = gmaps.distance_matrix(random, (dest.lat, dest.lng))

现在,您正在传递一个
Place
对象,其中需要一个
dict
tuple

我的意思是,回溯清楚地说明了需要传递什么类型的对象…它返回这个错误:AttributeError:“Place”对象没有属性“lat”
dir(dest)
返回什么?类似这样的东西>>['class','delattr','dict','dir','doc','eq','format','ge','getattribute','gt','hash','init','le','lt','module','ne',在该列表中查找与
lng
lat
相关的内容并调用它。
dest = self.destination
self.expected = gmaps.distance_matrix(random, (dest.lat, dest.lng))