Many have suggested a metronome and practicing keeping time with that, but if you're playing woith a group, you need to be able to keep time with them. They're not metronomes - so although a metronome will definitely help, I don't think it's the end of the answer.
I found my ability to play in a group change massively when I stopped just listening to the sounds I was making. I don't know whether you're (subconciously perhaps) doing this, but if you are, this might be part of the problem. I'll explain:
Having played with various groups, I have noticed that some people are used to playing alone and need to hear a lot of their own intrument among the rest of the group. Sure, we all need our own (guitar in my case) poked up a bit so that we can hear the detail of what we're doing, but you still need a fair amount of the other instruments to get a context of what's happening.
This goes further than what you can hear though: It's about what you're listening to.
Next time you play along with anything, a group or a metronome or maybe a backing track, try listening to the whole thing : every instrument, including yourself, and hear the music as the audience would, as opposed to concentrating on hearing just what you're playing, which is v tempting given you want to get it right!
Once you start hearing the music as a whole, it helps with a lot of things including an appropriate volume, timing, and is a great way of ensuring you're fitting in with the band rather than just playing your bit and hoping all's well.
It might be that you're already listening this way in which case it'll sound like I'm accusing you of being self-centred musically. Please ldon't take it that way - tis just a suggestion :-)