English subtitles

← Populate the Geofence List

Get Embed Code
4 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. So here's this simple function
    that I've created for
  2. populating the GeoFence list.
  3. This is my hash map, so
  4. for each entry in the hash map,
    I'm going to call it entry.
  5. I'm going to add to my GeoFence list,
  6. which is the array list
    we created earlier.
  7. A new GeoFence object
    using a GeoFence builder.
  8. Then this GeoFence builder I set
    a number of properties on it.
  9. I called set request ID with the key
    that was in the entry with the hashmap.
  10. I then called set circular region and
  11. here's where I specified the latitude
    and longitude of the GeoFence.
  12. And then the actual radius of
    the GeoFence defined in meters.
  13. I've just set one in my constants.
  14. I then set my expiration duration.
  15. And again, in my contents I just set
    the GeoFence expiration in milliseconds.
  16. When you look at the constants
    file you'll see these values and
  17. you'll be able to edit them as you like.
  18. And then I finally set the transition
    types that will trigger the geo fence.
  19. And these were GeoFence enter or
    GeoFence exit.
  20. And then I'd build the GeoFence.
  21. So to recap, it's very simple
    I iterate through my hash map.
  22. Each entry in my hash
    map I called entry.
  23. And then from that I can
    derive my latitude and
  24. my longitude that I use
    to define the GeoFence.
  25. And then I have constants for
    the radius of the GeoFence,
  26. the expiration of the GeoFence.
  27. And I pass all of these to the GeoFence
    builder to create a new GeoFence.
  28. And then that new GeoFence is
    added to my GeoFences list.
  29. And as you can see,
    that's all down here for me.
  30. So when this function is finished,
  31. I will now have this array list,
    called MGeoFence list,
  32. with a list of all my FeoFences, based
    on their latitude, their longitude,
  33. and my radius and my expiration times
    that I've defined as constants.