  We study possible correlations between ultrahigh energy cosmic rays (UHECRs),
observed by Auger, AGASA and Yakutsk, and nearby active galactic nuclei (AGNs)
and $Fermi$ sources. We consider the deflection effects by a Galactic magnetic
field (GMF) model constrained by the most updated measurements. We found that
the average deflection angles of UHECRs by the Galactic magnetic fields are
less than $4^\circ$. A correlation between the Auger cosmic-ray events and
nearby AGNs with a significance level of $\sim 4\sigma$ was found for the Auger
UHECR data sets with or without deflection correction. No correlation was found
between the AGASA/Yakutsk events with nearby AGNs. Marginal correlations
between the Auger events and the $Fermi$ sources, and between AGASA events and
$Fermi$ AGNs were found when the deflections calculated by the GMF model were
considered. However, no correlation was found between the Yakutsk data and
$Fermi$ sources. Some $Fermi$ sources are close to the arrival directions of
UHECR events detected by Auger, AGASA, and Yakutsk, most of which are probably
chance coincidence rather than objects producing UHECRs in the nearby Universe.
Four $Fermi$ sources, NGC 4945, ESO 323-G77, NGC 6951, and Cen A, within
100~Mpc have UHECR events within $3.1^{\circ}$ from their positions, which
could potentially be cosmic ray accelerators. However, the association can only
be confirmed if more UHECRs are preferably detected in these directions.
