The epicenter of an earthquake is determined by triangulation. This means that seismic data is needed from at least three different locations, and where this data intersects tells us the epicenter. When an earthquake occurs, it is recorded on numerous seismographs located in different directions.
The seismograms at these locations show when the first seismic waves, the primary waves, arrive and then when the next waves, the secondary waves, arrive. Knowing how fast each of these waves travel, scientists can calculate how far away the epicenter was from each seismograph.
What they don't know is the precise direction the waves came from –- the direction of the epicenter. Scientists then must use a map. Around each of three seismograph locations, a circle is drawn on the map with a radius that equals the known distance to the epicenter. These three circles intersect at a single point. This point is the location of the earthquake's epicenter.
And while we can pinpoint where an earthquake originated, we haven't gotten much better at predicting them. We can detect earthquakes several seconds in advance like researchers at the University of California Berkeley did for the South Napa earthquake. But we can't predict them days or months into the future.
As we better understand how they occur we can construct buildings to withstand a certain amount of shaking and even take fault lines into account as we build new cities. Aside from that, having an emergency kit can help and perhaps one day, the early warning system will give us not just seconds but minutes.