© 2016 The Authors Published by Oxford University Press on behalf of the Royal Astronomical Society.We study the stellar-to-halo mass relation of central galaxies in the range 9.7 <log10(M*/h-2 M⊙) <11.7 and z <0.4, obtained from a combined analysis of the Kilo Degree Survey (KiDS) and the Galaxy And Mass Assembly (GAMA) survey. We use ~100 deg2 of KiDS data to study the lensing signal around galaxies for which spectroscopic redshifts and stellar masses were determined by GAMA. We show that lensing alone results in poor constraints on the stellar-to-halo mass relation due to a degeneracy between the satellite fraction and the halo mass, which is lifted when we simultaneously fit the stellar mass function. At M* > 5 × 1010 h-2 M⊙, the stellar mass increases with halo mass as ~Mh0.25. The ratio of dark matter to stellar mass has a minimum at a halo mass of 8 × 1011 h-1 M⊙ with a value of Mh/M* = 56-10+16 [h]. We also use the GAMA group catalogue to select centrals and satellites in groups with five or more members, which trace regions in space where the local matter density is higher than average, and determine for the first time the stellar-to-halo mass relation in these denser environments. We find no significant differences compared to the relation from the full sample, which suggests that the stellar-to-halo mass relation does not vary strongly with local density. Furthermore, we find that the stellar-to-halo mass relation of central galaxies can also be obtained by modelling the lensing signal and stellar mass function of satellite galaxies only, which shows that the assumptions to model the satellite contribution in the halo model do not significantly bias the stellar-to-halo mass relation. Finally, we show that the combination of weak lensing with the stellar mass function can be used to test the purity of group catalogues.