Context. Active longitudes have been found in various manifestations of solar activity. The longitudinal distribution of, e.g., sunspots and solar X-ray flares shows two persistent preferred longitudes separated by roughly 180 degrees. We previously studied solar X-ray flares using an improved version of a dynamic, differentially rotating coordinate system and found enhanced rotational asymmetry and rotation parameter values that are consistent for the three classes of X-ray flares. Aims. We aim to find the optimal values of rotation parameters of active longitudes of sunspots for several different time intervals and separately for the two solar hemispheres. Methods. We perform a global study of the longitudinal location of sunspots (all sunspots and first appearance sunspots) using a refined version of a dynamic, differentially rotating coordinate system. Results. We find that the rotation parameters for sunspots are in good agreement with those obtained for X-ray flares using the same method. The improved method typically finds somewhat faster equatorial rotation with better accuracy. The improved treatment also leads to a larger non-axisymmetry. Rotation parameters for all sunspots and first appearances closely agree with each other, but nonaxisymmetry is systematically larger for all sunspots than for first appearances, suggesting that strong fields follow more closely the pattern of active longitudes. The refined method emphasizes hemispheric differences in rotation. Over the whole interval, the mean rotation in the southern hemisphere is slower than in the north. We also find significant temporal variability in the two rotation parameters over the 136-year interval. Interestingly, the long-term variations (trends and residual oscillations) in solar rotation are roughly the opposite in the northern and southern hemispheres. Conclusions. Rotation parameters vary differently with time in the northern and southern hemispheres. Both sunspots and flares strongly suggest that the northern hemisphere rotated considerably faster but the southern hemisphere slightly slower than the Carrington rotation rate during the last three solar cycles.