Rock.Model.DeviceService.GetByGeocode C# (CSharp) Method

GetByGeocode() public method

Finds the matching device for the given lat/long coordinates. The given coordinates must intersect one of the stored GeoFence values to be a match. Use the deviceTypeValueId to constrain matching to only certain device types.
public GetByGeocode ( double latitude, double longitude, int deviceTypeValueId ) : Device
latitude double Latitude of the mobile phone/kiosk.
longitude double Longitude of the mobile phone/kiosk.
deviceTypeValueId int Longitude of the mobile phone/kiosk.
return Device
        public Device GetByGeocode( double latitude, double longitude, int deviceTypeValueId )
        {
            Device device = null;
            DbGeography aLocation = DbGeography.FromText( string.Format("POINT({0} {1})", longitude, latitude) );

            device = Queryable()
                .Where( d =>
                    d.DeviceTypeValueId == deviceTypeValueId &&
                    d.Location != null &&
                    aLocation.Intersects( d.Location.GeoFence ) )
                .FirstOrDefault();

            return device;
        }