Javascript 如何检查firebase data()在地质点字段上的空值

Javascript 如何检查firebase data()在地质点字段上的空值,javascript,firebase,google-cloud-firestore,geolocation,Javascript,Firebase,Google Cloud Firestore,Geolocation,我正在添加用户地理点,在将数据推送到阵列之前,我想检查snapShot.data().location.geopoint是否为null,但我一直收到以下错误: 错误错误:未捕获(承诺中):TypeError:无法读取未定义的属性“geopoint” TypeError:无法读取未定义的属性“geopoint” 您可以使用snapshot.get(fieldPath)API()并执行以下操作: 您可以使用snapshot.get(fieldPath)API()并执行以下操作: 添加你的Fires

我正在添加用户地理点,在将数据推送到阵列之前,我想检查snapShot.data().location.geopoint是否为null,但我一直收到以下错误:

错误错误:未捕获(承诺中):TypeError:无法读取未定义的属性“geopoint”
TypeError:无法读取未定义的属性“geopoint”

您可以使用
snapshot.get(fieldPath)
API()并执行以下操作:


您可以使用
snapshot.get(fieldPath)
API()并执行以下操作:


添加你的Firestore添加你的Firestore工作得像个符咒。谢谢你,工作很有魅力。非常感谢。
let userLat = 0;
let userLong = 0;

if (snapShot.get("location.geopoint")) {
  userLat = snapShot.get("location.geopoint").latitude;
  userLong = snapShot.get("location.geopoint").longitude;
}