简体   繁体   English

如何在python中将firebase firestore geopoint转换为latlng

[英]How to convert firebase firestore geopoint to a latlng in python

I have geopoint fields in firestore.我在firestore中有地理点字段。 I want to be able to convert the geopoint back to latlng.我希望能够将地理点转换回 latlng。 From firestore documentation, the .getLatitude() and getLongitude() should do the trick.Firestore文档中, .getLatitude()getLongitude()应该可以解决问题。 But this doesn't seem to work with Python.但这似乎不适用于 Python。 I keep getting the error:我不断收到错误:

print(geopoint.getLatitude())打印(地理点。getLatitude())

AttributeError: 'GeoPoint' object has no attribute 'getLatitude' AttributeError: 'GeoPoint' 对象没有属性 'getLatitude'

How can I get the geopoint values in Python?如何在 Python 中获取地理点值?

geopoint = field['location']

print(geopoint.getLatitude()) 
print(geopoint.getLongitude()) 

GeoPoint 具有经度和纬度属性,请参考这些而不是您正在使用的方法。

As @spmaddox mentioned, with Python, the get method is not required.正如@spmaddox 所提到的,对于 Python,不需要 get 方法。 So the following works:所以以下工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM