谷歌地图find_place()位置参数问题

时间:2019-04-25 13:37:21

标签: python api google-maps

我需要为项目使用googlemaps / google-maps-services-python,这是有问题的。

我想使用find_place():

def find_place(client, input, input_type, fields=None, location_bias=None,
                language=None):

但是当我启动脚本

import googlemaps
from datetime import datetime


class Place:

    def __init__(self, words):
        self.words = words
        self.key = 'Key'
        self.gmaps = googlemaps.Client(key=self.key)


place = Place(['place to find'])
print(place.key)
loca = place.gmaps.find_place(self.key,"place to find","textquery",['place_id','formatted_address'])
print(loca)

有问题:


Traceback (most recent call last):
  File "gpbapp/program/place.py", line 15, in <module>
    loca = place.gmaps.find_place(place.key,place.words[0],"textquery",['place_id','formatted_address'])
  File "C:\Users\krfou\Documents\OPENCLASSROOMS\p7\env\lib\site-packages\googlemaps\client.py", line 365, in wrapper
    result = func(*args, **kwargs)
  File "C:\Users\krfou\Documents\OPENCLASSROOMS\p7\env\lib\site-packages\googlemaps\places.py", line 94, in find_place
    "the given value is invalid: '%s'" % input_type)
ValueError: Valid values for the `input_type` param for `find_place` are 'textquery' or 'phonenumber', the given value is invalid: 'disneyland, paris'
(env)

如果我愿意

loca = place.gmaps.find_place(place.key,"textquery",['place_id','formatted_address'])

它可以工作,但是我没有任何结果(因为输入不再存在)。

{'candidates': [], 'status': 'ZERO_RESULTS'}

位置参数之间存在混淆,好像有一个隐藏的参数...会发生什么?

1 个答案:

答案 0 :(得分:2)

如果这样做不行

loca = place.gmaps.find_place(client=place.key,input="place to find", input_type="textquery",fields=['place_id','formatted_address'])