目前我正在使用Google API for Python。 我使用谷歌广告库作为谷歌距离矩阵的输入参数。 这就是我所拥有的:
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
我想我需要将来自googlePlace的* args作为元组(或字符串?)作为google距离矩阵的输入传递。
许多人建议使用arg = list (arg)
解压缩* args。但我发现事实并非如此。
我打印出了自我推销。这就是我得到的:
<Place name="Menara Citicon", lat=-6.1926896, lng=106.7976679>
我认为这是问题
我该怎么办?谢谢
答案 0 :(得分:0)
你可以使用
dest = self.destination
self.expected = gmaps.distance_matrix(random, (dest.lat, dest.lng))
目前,您正在传递Place
对象,其中需要dict
或tuple
。