Fireship · @fireship

Firestore Geoquery

Uploaded July 11, 2018 · Length 8:26

Firestore Geoquery

Summary

Firestore Geoquery tutorial using Angular and Google Maps to build a real-time geolocation feature with Firestore and Geo Fire X library.

  • firestore geoquery
  • angular google maps
  • geolocation feature
  • geo fire x library
  • firebase geolocation

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:06

    real-time geolocation is behind some of

  3. 0:08

    the most awesome apps in the world such

  4. 0:10

    as uber Instagram and ways to name a few

  5. 0:12

    but building these features from scratch

  6. 0:14

    requires a lot of complex math and

  7. 0:16

    advanced data modeling but fortunately

  8. 0:18

    there's tools we can use to build

  9. 0:19

    features like this without any

  10. 0:21

    trigonometry and we can do it in the

  11. 0:23

    next few minutes if you're new here like

  12. 0:24

    and subscribe and if you're serious

  13. 0:26

    about building apps like this consider

  14. 0:27

    becoming a pro member at angular

  15. 0:29

    firebase com

  16. 0:30

    our goal today is to use firestore and

  17. 0:32

    angular google maps to build a real-time

  18. 0:34

    geolocation feature so we'll be able to

  19. 0:37

    say give us all the documents that are

  20. 0:38

    within X kilometers of some center point

  21. 0:40

    and have that query update in real time

  22. 0:43

    but before we get going I have a couple

  23. 0:45

    examples of real-world angular firebase

  24. 0:47

    apps that use geolocation features the

  25. 0:49

    first one is cipher links which was

  26. 0:51

    built by an angular firebase Pro member

  27. 0:53

    and is essentially a LinkedIn for coders

  28. 0:55

    that allows you to find programmers

  29. 0:57

    geographically based on a filtered set

  30. 0:59

    of criteria and the next one is pod

  31. 1:01

    mapped word which is an open source

  32. 1:03

    project using angular and firebase that

  33. 1:05

    allows you to locate podcasts from

  34. 1:07

    around the world

  35. 1:08

    check out those links in the description

  36. 1:09

    but the next thing I want to talk about

  37. 1:11

    is how geo queries actually work because

  38. 1:13

    they're a lot different than a normal

  39. 1:14

    query that you would make in firestore

  40. 1:16

    so we create this fractal pattern where

  41. 1:19

    we have a grid of numbers and letters

  42. 1:20

    that segment the globe then we can build

  43. 1:23

    out a string value by repeating this

  44. 1:25

    pattern over and over again inside of

  45. 1:26

    each cell so every additional character

  46. 1:29

    in the string will be an additional

  47. 1:30

    level of precision for the location

  48. 1:32

    we're going to be saving our geohashes

  49. 1:34

    as 9 characters which is precise to

  50. 1:37

    about four and a half meters squared if

  51. 1:40

    you go to movable-type store you can

  52. 1:42

    explore the bounding boxes for different

  53. 1:44

    geohashes if we want to query firestore

  54. 1:47

    for all of the documents inside of a

  55. 1:49

    single geo hash it's actually pretty

  56. 1:51

    straightforward we can set the starting

  57. 1:53

    point as the Geo hash the endpoint as

  58. 1:55

    the hash plus a high Unicode character

  59. 1:58

    then we can order by the property it has