首页 > 解决方案 > 如何将变量放入 geolocator.reverse() 函数?

问题描述

我有lat1lng1设置。当我尝试时:

location = geolocator.reverse('lat1', 'lng1')

它给了我错误:

类型错误

Traceback (most recent call last)
<ipython-input-65-bef81ce5884b> in <module>
----> 1 location = geolocator.reverse('lat1', 'lng1')

TypeError: reverse() takes 2 positional arguments but 3 were given

当我在没有'的情况下尝试它时,它给了我一个语法错误。

标签: pythongeopy

解决方案


您可以使用以下代码:

location = geolocator.reverse("{}, {}".format(lat1, lng1))

上面的代码将变量格式化为.reverse()方法的字符串。


推荐阅读