在主python程序中调用google-map函数并在python中传递参数

垫片

我需要定义一个包含两个参数的函数。参数在调用其中的函数的主 python 程序中提供。该函数调用 googlemapsapi 来计算旅行时间。主程序可以调用该函数,但不接受提供的参数。在没有提供参数的情况下执行的函数。

功能:

def travel_time(origin,destination):
return value

print("Below is Drive Time");
now = datetime.now()

directions_result_drive = gmaps.directions(origin,
                                 destination,
                                   mode="driving",                                     
                                 departure_time=now
                                )
value=round(float((directions_result_drive[0]['legs'][0]['duration']

['值'])/3600),1)

主要程序如下:

from travel_function import travel_time
origin = input("origin is:",)
destination = input("destination is:",)
print(travel_time(origin,destination));

根据提供的参数,它应该给出旅行时间。例如 Origin=NewYork, Destination="Boston",返回的值应该是大约。4个小时

梅林·卡茨

看起来唯一的问题是 return 语句在顶部,这应该有效:

def travel_time(origin, destination):

    print("Below is Drive Time")
    now = datetime.now()

    directions_result_drive = gmaps.directions(
        origin,
        destination,
        mode="driving",                                     
        departure_time=now
    )
    value = round(float((directions_result_drive[0]['legs'][0]['duration']['value'])/3600),1)
    return value

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章