Location / distanceFrom / Geofence

Hi,

I just can’t seem to get the distanceFrom function working :sweat:

Here’s the rule file:

import org.openhab.core.library.types.*

// GEOFENCES
// 1. Home
val PointType HomeLoc = new PointType(‘12.3456,56.4321’)
// 2. Office
val PointType OfficeLoc = new PointType(‘65.4321,1.234’)

 rule "updt geoposition"
    when
        Item mqttMyPosition received update
    then
          val PointType myPos = new PointType(mqttMyPosition.state.toString)
        val officeDistance = OfficeLoc.distanceFrom(myPos)
    end    

And the error:
2016-11-06 10:15:14.768 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'updt geoposition': The name '<XFeatureCallImplCustom>.distanceFrom(<XFeatureCallImplCustom>)' cannot be resolved to an item or type.

What am I doing wrong?

Does the example given here not work as well? Which openHAB version are you running?

1 Like

Ah, I upgraded from 1.7.1 to 1.8.3 and it’s working, thanks. Forgot I was running an older version :slight_smile:

thanks for posting

Can you tell:
… does it really grab the lon lat out of the raw string?
Is the mqttMyPosition a mqttitude or mqtt source?
E.g. mqttitude allows only to resolve to a switch item, while mqtt provides the full string published by OwnTracks.

My advice would be to use the MQTT binding with OwnTracks, since you get more flexibility. A PointType can take a string in the form lat,long[,elevation] (meaning elevation is optional). I think the topic below has more about it:

1 Like

Thanks… makes sense… as the enter | leave into regions is as well established by using mqtt… :slight_smile:

Hello, I am also getting this error when trying to call the DistanceFrom method: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.core.library.items.LocationItem.distanceFrom(org.eclipse.smarthome.core.library.items.LocationItem) on instance: locationMarkus (Type=LocationItem, … > using one of the latest snapshot version of openhab2 > any idea?