जियोस्पेशल क्वेरी का इस्तेमाल करना

जगह की जानकारी देने वाली सेवाओं को बनाने के लिए, Cloud Firestore में जियोस्पेशल क्वेरी की जा सकती हैं. उदाहरण के लिए, किसी उपयोगकर्ता और आस-पास के दिलचस्पी के पॉइंट के बीच की दूरी पता की जा सकती है. साथ ही, उन्हें सबसे पास से सबसे दूर के क्रम में सॉर्ट किया जा सकता है.

एडिशन से जुड़ी ज़रूरी शर्तें

जियोस्पेशल क्वेरी की सुविधा के लिए, Firestore Enterprise एडिशन डेटाबेस की ज़रूरत होती है.

शुरू करने से पहले

जियोस्पेशल क्वेरी करने के लिए, सबसे पहले आपको उन फ़ील्ड के लिए जियोस्पेशल इंडेक्स बनाने होंगे जिनमें आपको खोजना है.

जियोस्पेशल क्वेरी करना

जियोस्पेशल क्वेरी करने के लिए, search(...) स्टेज के query पैरामीटर में geoDistance एक्सप्रेशन का इस्तेमाल करें.

सिर्फ़ 'से कम या उसके बराबर' (<=) ऑपरेटर का इस्तेमाल किया जा सकता है. दूरी को मीटर में मापा जाता है.

उदाहरण के लिए, यहां दी गई क्वेरी, लिस्ट किए गए जियोपॉइंट से 1,000 मीटर के दायरे में मौजूद सभी रेस्टोरेंट ढूंढती है.

Web

firestore.pipeline().collection('restaurants')
  .search({
    query: field('location')
      .geoDistance(new GeoPoint(38.989177, -107.065076))
      .lessThan(1000 /* m */)
  });
iOS
firestore.pipeline().collection("restaurants")
    .search(
        query: Field("location")
            .geoDistance(GeoPoint(latitude: 38.989177, longitude: -107.065076))
            .lessThan(1000)
    )
Android
firestore.pipeline()
        .collection("restaurants")
        .search(new SearchOptions()
                .withQuery(field("location")
                        .geoDistance(new GeoPoint(38.989177, -107.065076))
                        .lessThan(1000 /* meters */)));
Node.js
firestore.pipeline().collection('restaurants')
  .search({
    query: field('location')
      .geoDistance(new GeoPoint(38.989177, -107.065076))
      .lessThan(1000 /* m */)
  });