Fireship · @fireship
Firestore Geoquery
Uploaded July 11, 2018 · Length 8:26
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.
- 0:00
[Music]
- 0:06
real-time geolocation is behind some of
- 0:08
the most awesome apps in the world such
- 0:10
as uber Instagram and ways to name a few
- 0:12
but building these features from scratch
- 0:14
requires a lot of complex math and
- 0:16
advanced data modeling but fortunately
- 0:18
there's tools we can use to build
- 0:19
features like this without any
- 0:21
trigonometry and we can do it in the
- 0:23
next few minutes if you're new here like
- 0:24
and subscribe and if you're serious
- 0:26
about building apps like this consider
- 0:27
becoming a pro member at angular
- 0:29
firebase com
- 0:30
our goal today is to use firestore and
- 0:32
angular google maps to build a real-time
- 0:34
geolocation feature so we'll be able to
- 0:37
say give us all the documents that are
- 0:38
within X kilometers of some center point
- 0:40
and have that query update in real time
- 0:43
but before we get going I have a couple
- 0:45
examples of real-world angular firebase
- 0:47
apps that use geolocation features the
- 0:49
first one is cipher links which was
- 0:51
built by an angular firebase Pro member
- 0:53
and is essentially a LinkedIn for coders
- 0:55
that allows you to find programmers
- 0:57
geographically based on a filtered set
- 0:59
of criteria and the next one is pod
- 1:01
mapped word which is an open source
- 1:03
project using angular and firebase that
- 1:05
allows you to locate podcasts from
- 1:07
around the world
- 1:08
check out those links in the description
- 1:09
but the next thing I want to talk about
- 1:11
is how geo queries actually work because
- 1:13
they're a lot different than a normal
- 1:14
query that you would make in firestore
- 1:16
so we create this fractal pattern where
- 1:19
we have a grid of numbers and letters
- 1:20
that segment the globe then we can build
- 1:23
out a string value by repeating this
- 1:25
pattern over and over again inside of
- 1:26
each cell so every additional character
- 1:29
in the string will be an additional
- 1:30
level of precision for the location
- 1:32
we're going to be saving our geohashes
- 1:34
as 9 characters which is precise to
- 1:37
about four and a half meters squared if
- 1:40
you go to movable-type store you can
- 1:42
explore the bounding boxes for different
- 1:44
geohashes if we want to query firestore
- 1:47
for all of the documents inside of a
- 1:49
single geo hash it's actually pretty
- 1:51
straightforward we can set the starting
- 1:53
point as the Geo hash the endpoint as
- 1:55
the hash plus a high Unicode character
- 1:58
then we can order by the property it has


