0
votes

I have geopoint fields in firestore. I want to be able to convert the geopoint back to latlng. From firestore documentation, the .getLatitude() and getLongitude() should do the trick. But this doesn't seem to work with Python. I keep getting the error:

print(geopoint.getLatitude())

AttributeError: 'GeoPoint' object has no attribute 'getLatitude'

How can I get the geopoint values in Python?

geopoint = field['location']

print(geopoint.getLatitude()) 
print(geopoint.getLongitude()) 
2
documentSnapshot.to_dict() is not working for me. So I referred to github.com/GoogleCloudPlatform/python-docs-samples/blob/master/… But how can I add GeoPoint in this class?pratiked

2 Answers

3
votes

GeoPoint has longitude and latitude attributes, reference these instead of the methods you’re using.

0
votes

As @spmaddox mentioned, with Python, the get method is not required. So the following works:

print(geopoint.latitude)
print(geopoint.longitude)