Just use XPos and YPos to find your grid location from actual location. Then use XLoc and YLoc on that returned value to do the actual 'snapping'.

Think of it like rounding a decimal value.