From d88f4594ac690936a36d0f1d6c760327321925e0 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Fri, 24 Feb 2017 06:25:50 -0700 Subject: [PATCH] distances on geofence, fixes #141 --- controller/fence.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/controller/fence.go b/controller/fence.go index 2e43723d..3cf8b764 100644 --- a/controller/fence.go +++ b/controller/fence.go @@ -155,14 +155,19 @@ func fenceMatch(hookName string, sw *scanWriter, fence *liveFenceSwitches, metas break } sw.mu.Lock() + var distance float64 + if fence.distance { + distance = details.obj.CalculatedPoint().DistanceTo(geojson.Position{X: fence.lon, Y: fence.lat, Z: 0}) + } sw.fmap = details.fmap sw.fullFields = true sw.msg.OutputType = server.JSON sw.writeObject(ScanWriterParams{ - id: details.id, - o: details.obj, - fields: details.fields, - noLock: true, + id: details.id, + o: details.obj, + fields: details.fields, + noLock: true, + distance: distance, }) if sw.wr.Len() == 0 {