第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用Firestore運行地理“附近”查詢?

如何使用Firestore運行地理“附近”查詢?

Firebase的新Firestore數(shù)據(jù)庫本身是否支持基于位置的地理位置查詢?即查找10英里內(nèi)的帖子,還是找到50個最近的帖子?我看到有一些實時Firebase數(shù)據(jù)庫的現(xiàn)有項目,例如geofire等項目,這些項目也可以改編成Firestore嗎?
查看完整描述

3 回答

?
皈依舞

TA貢獻1851條經(jīng)驗 獲得超3個贊

更新:Firestore當前不支持實際的GeoPoint查詢,因此盡管以下查詢成功執(zhí)行,但它僅按緯度而不是經(jīng)度進行過濾,因此將返回許多附近的結(jié)果。最好的解決方案是使用geohash。要了解自己如何做類似的事情,請觀看此視頻。


這可以通過創(chuàng)建一個小于查詢的邊界框來完成。至于效率,我不能說。


請注意,應(yīng)檢查緯度/經(jīng)度偏移?1英里的精度,但這是一種快速的方法:


SWIFT 3.0版本


func getDocumentNearBy(latitude: Double, longitude: Double, distance: Double) {


    // ~1 mile of lat and lon in degrees

    let lat = 0.0144927536231884

    let lon = 0.0181818181818182


    let lowerLat = latitude - (lat * distance)

    let lowerLon = longitude - (lon * distance)


    let greaterLat = latitude + (lat * distance)

    let greaterLon = longitude + (lon * distance)


    let lesserGeopoint = GeoPoint(latitude: lowerLat, longitude: lowerLon)

    let greaterGeopoint = GeoPoint(latitude: greaterLat, longitude: greaterLon)


    let docRef = Firestore.firestore().collection("locations")

    let query = docRef.whereField("location", isGreaterThan: lesserGeopoint).whereField("location", isLessThan: greaterGeopoint)


    query.getDocuments { snapshot, error in

        if let error = error {

            print("Error getting documents: \(error)")

        } else {

            for document in snapshot!.documents {

                print("\(document.documentID) => \(document.data())")

            }

        }

    }


}


func run() {

    // Get all locations within 10 miles of Google Headquarters

    getDocumentNearBy(latitude: 37.422000, longitude: -122.084057, distance: 10)

}


查看完整回答
反對 回復(fù) 2019-10-06
?
四季花海

TA貢獻1811條經(jīng)驗 獲得超5個贊

自@monkeybonkey首次提出此問題以來,已經(jīng)引入了一個新項目。該項目稱為GEOFirestore。


使用此庫,您可以在一個圓圈內(nèi)執(zhí)行查詢,例如查詢文檔:


  const geoQuery = geoFirestore.query({

    center: new firebase.firestore.GeoPoint(10.38, 2.41),

    radius: 10.5

  });

您可以通過npm安裝GeoFirestore。您將必須單獨安裝Firebase(因為它是GeoFirestore的對等依賴項):


$ npm install geofirestore firebase --save


查看完整回答
反對 回復(fù) 2019-10-06
  • 3 回答
  • 0 關(guān)注
  • 691 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號