add max_accuracy option in location agent

stvnrlly 10 years ago
parent
commit
9550fa5bf6
1 changed files with 7 additions and 2 deletions
  1. 7 2
      app/models/agents/user_location_agent.rb

+ 7 - 2
app/models/agents/user_location_agent.rb

@@ -10,6 +10,8 @@ module Agents
10 10
 
11 11
 
12 12
         Your POST path will be `https://#{ENV['DOMAIN']}/users/#{user.id}/update_location/:secret` where `:secret` is specified in your options.
13
+
14
+        If you want to only keep more precise locations, set `max_accuracy` to the upper bound, in meters.
13 15
       MD
14 16
     end
15 17
 
@@ -34,7 +36,10 @@ module Agents
34 36
     end
35 37
 
36 38
     def default_options
37
-      { 'secret' => SecureRandom.hex(7) }
39
+      {
40
+        'secret' => SecureRandom.hex(7),
41
+        'max_accuracy' => ''
42
+      }
38 43
     end
39 44
 
40 45
     def validate_options
@@ -68,7 +73,7 @@ module Agents
68 73
     def handle_payload(payload)
69 74
       location = Location.new(payload)
70 75
 
71
-      if location.present?
76
+      if (location.present? && (payload["accuracy"] < interpolated[:max_accuracy]))
72 77
         create_event payload: payload, location: location
73 78
       end
74 79
     end