2017-10-06 82 views
7

在數據庫UI中,我可以創建類型爲geopoint的字段。提供值後,它看起來像這樣:如何在Firebase Cloud Firestore中保存GeoPoint?

location: [1° N, 1° E] 

我想通過客戶端SDK(網絡)保存到數據庫。 基於微博反饋我試圖以GeoJSON,COORDS陣列和COORDS對象:

location: [1, 2]; 
location: { 
    latitude: 1, 
    longitude: 2, 
}; 
location: { 
    "type": "Feature", 
    "geometry": { 
     "type": "Point", 
     "coordinates": [125.6, 10.1] 
    } 
} 

其中沒有導致在數據庫中的GeoPoint類型。它們只保存爲對象/數組。

如何通過Web SDK將GeoPoint保存在Firebase Cloud Firestore中?

回答

10

該公司的FireStore軟件開發工具包包括一個GeoPoint class,所以你必須保存的位置是這樣的:

{ 
    location: new firebase.firestore.GeoPoint(latitude, longitude) 
} 
+0

的作品就像一個魅力! – ProblemsOfSumit

+0

你導入了什麼來獲得GeoPoint類?我試過firebase和firebase /應用程序,但沒有去。我在一個firebase-admin應用程序。 – neonguru

+0

@neonguru - 你有沒有更新到最新的管理員SDK?它應該在那裏https://firebase.google.com/docs/reference/admin/node/admin.firestore.GeoPoint – Scarygami

相關問題