Earthquakes occur along the plate boundaries; however, the exact location of an earthquake is determined by using seismographs.
A seismograph is an instrument used by the scientists (known as seismologists) to record an earthquake. A seismogram is the recording made by a seismograph.
The seismograph consists of a mass which is attached to a fixed base. When the earthquake occurs, the base shakes along with the ground. On the other hand, the string to which the mass is attached absorbs the movement and ensures that the mass stays fixed. This relative motion of the base with respect to the mass is recorded.
Interestingly, a seismograph can only tell how far away an earthquake occurred and not its directions. Scientists use a set of three seismographs to determine the exact location of an earthquake through a process called triangulation. Using each seismograph, scientists can draw a circle whose radius is equal to the distance of that seismograph from the earthquake. The point of intersection of three such circles (recorded by three independent seismographs) will give us the exact location of an earthquake.
I hope this helps.