Search code examples
pythongeopy

How do I put a variable in a geolocator.reverse() function?


I have lat1 and lng1 set. And when I try:

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

It gives me the error:

TypeError

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

and when I try it without the ',' it gives me a syntax error.


Solution

  • You can use the following code:

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

    The code above formats the variables as a string for the .reverse() method.