-2

currently I am working with Google API for Python. I am using google Place Library as an input parameter for google Distance Matrix. This is what I have:

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)

And I got this series of errors

 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

I think I need to pass *args from googlePlace as tuple (or string?) as input for google distance matrix.

Many suggest to use arg = list (arg) to unpacked the *args. But I found that's not the case.

I printed out self.destination. This is what I got:

<Place name="Menara Citicon", lat=-6.1926896, lng=106.7976679>

I think this is the problem

What should I do with this? Thanks

dya
  • 195
  • 1
  • 2
  • 16

1 Answers1

0

You can just use

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

Right now, you are passing a Place object, where a dict or a tuple is required.

  • It returns this error: AttributeError: 'Place' object has no attribute 'lat' – dya Jan 10 '17 at 05:37
  • What does `dir(dest)` return? –  Jan 10 '17 at 05:39
  • something like this >> ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', – dya Jan 10 '17 at 05:43
  • 1
    Look for something that relates to `lng` and `lat` in that list and call it. –  Jan 10 '17 at 05:44