Installation geopy python 2.7

0

I have python 2.7.12 installed on my computer (ubuntu 16.04) and installed geopy (1.11). But when I try to run my script, this error appears:

from geopy.distance import  lonlat, distance




ImportError: cannot import name lonlat

Someone knows how to tell me why? And how do I fix it?

    
asked by anonymous 06.09.2018 / 11:41

1 answer

1

Try to use distance as follows:

Existing example in geopy documentation

from geopy import distance

newport_ri = (41.49008, -71.312796)
cleveland_oh = (41.499498, -81.695391)
print(distance.distance(newport_ri, cleveland_oh).miles)

For lonlat you can do the same thing:

from geopy import distance

point = distance.lonlat(41.49008, -71.312796)
print(point)

Edited after marked as accepted.

After checking the comments and continuing to point the error, it was verified that the distance.lonlat function did not exist in version 1.11.0 of the geopy package. It has been added to version 1.14.0 and can be seen by the release comment:

  

1.14.0

     

ADDED: geopy.distance.lonlat function for conveniently converting (x,   and, [z]) coordinate tuples to the Point instances, which use (y, x,   [z]).

For this reason, the error occurs in import. In the comments it was also indicated that the import used in the question is not wrong and can be used as long as the right version of geopy is installed.

The code that uses distance works in version 1.11.0 with the import done as it is in this response and not as it is in the question because distance exists in version 1.11.0, but it points to Vincenty method. In the most recent version, distance started to point to the Geodesic method and included the lonlat() function.

    
06.09.2018 / 13:50