Fireship · @fireship

Location-based Queries with GeoFire and Angular Google Maps

Uploaded August 25, 2017 · Length 5:36

Location-based Queries with GeoFire and Angular Google Maps

Summary

Implement location-based queries with GeoFire and Angular Google Maps to display items within a certain radius of the user's location.

  • angular google maps
  • geofire
  • location-based queries
  • firebase geo fire
  • angular google maps tutorial
  • location driven app

Transcript preview

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

  1. 0:00

    when building a location driven app it's

  2. 0:02

    critical to be able to query data based

  3. 0:04

    on that current user's location in this

  4. 0:06

    episode we're going to use angular

  5. 0:08

    Google Maps along with firebase geo fire

  6. 0:11

    to accomplish this task the app will

  7. 0:13

    first detect the current users location

  8. 0:15

    and then query firebase for any items

  9. 0:17

    within a certain radius of that location

  10. 0:19

    then we'll display those items on the

  11. 0:21

    map along with their distance from the

  12. 0:23

    current user to help us along the way

  13. 0:25

    we're going to use the angular Google

  14. 0:27

    Maps package which includes several

  15. 0:29

    pre-built components and directives for

  16. 0:31

    common Google Maps elements you can

  17. 0:33

    install it with NPM install a GM / Corps

  18. 0:36

    flag save from there you need to go to

  19. 0:39

    the Google cloud platform console and

  20. 0:41

    enable the Google Maps API once enabled

  21. 0:44

    you can generate an API key and then

  22. 0:47

    we'll use that API key in that angular

  23. 0:49

    environment here we already have

  24. 0:50

    firebase configured via angularfire -

  25. 0:53

    and then we'll also add our Google Maps

  26. 0:55

    API key here then we can go over to our

  27. 0:57

    app module and we'll import the

  28. 0:59

    environment as well as the angularfire

  29. 1:01

    module and angular Google Maps then we

  30. 1:04

    can pass a GM or Google Maps API key

  31. 1:07

    when we import it in the module from

  32. 1:10

    here we'll go ahead and create a new

  33. 1:11

    component to handle the map called

  34. 1:13

    Google map then we need to give the map

  35. 1:15

    a CSS style we want it to be full screen

  36. 1:18

    so we'll just do 100 width and height in

  37. 1:20

    the HTML we'll wrap the map in a div so

  38. 1:23

    it only displays if the latitude and

  39. 1:24

    longitude is defined then we can use the

  40. 1:27

    AGM map selector and pass it the

  41. 1:29

    latitude and longitude as input

  42. 1:31

    arguments this will define the center

  43. 1:34

    point of the map then we can nest ajm

  44. 1:37

    markers inside the map and display them

  45. 1:39

    at whichever coordinates we want and if

  46. 1:41

    we want that marker to have a popup

  47. 1:43

    window then we can add the ajm info

  48. 1:45

    window and we can transclude any HTML we

  49. 1:48

    want in here so now we just need to get

  50. 1:51

    the current users location so we can do

  51. 1:53

    this in that component by defining a

  52. 1:55

    Latin longitude variable then during ng

  53. 1:58

    on an it we tap into the global

  54. 1:59

    navigator object and we call get current