VitalWall

How to Build a Live Earthquake Feed From USGS

One public feed, one wall, no code beyond the embed tag.

How to Build a Live Earthquake Feed From USGS

The U.S. Geological Survey publishes the earthquakes it records as public JSON feeds, updated every minute. With VitalWall you can turn one of those feeds into a live list on your site or a TV. No code beyond the embed tag.

See it running on our live earthquakes demo, then build your own below.

VitalWall's earthquakes demo: a live list of magnitude 4.5 and larger earthquakes from the past day, each with its magnitude in a colored circle and the place beside it

Each row is one earthquake: the magnitude in a colored circle, the place next to it. When USGS adds a new one, it shows up on the wall at the next refresh. Nobody sends us anything.

What you need

  • A VitalWall account.
  • The site where the wall will live, or a TV. That's it. The USGS feed needs no key.

The feed

USGS has a family of GeoJSON summary feeds: past hour, past day, past 7 days and past 30 days, each at several magnitude cutoffs. We use the magnitude 4.5 and up, past day feed:

https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson

Here's part of what it returned when we checked it, cut down to the fields this recipe uses:

{ "type": "FeatureCollection", "metadata": { "title": "USGS Magnitude 4.5+ Earthquakes, Past Day", "count": 8 }, "features": [ { "properties": { "mag": 4.6, "place": "south of the Fiji Islands", "alert": null, "type": "earthquake" }, "id": "us6000uctj" }, { "properties": { "mag": 5.4, "place": "224 km NE of Bitung, Indonesia", "alert": "green", "type": "earthquake" }, "id": "us6000ucrb" } ] }

The earthquakes sit in the features array, newest first. Inside each one, properties.place is the location and properties.mag is the magnitude. Those two are the wall.

Step 1: Create the wall

In your VitalWall dashboard, add a new wall. Give it a name, like "Earthquakes", and add the domain of the site you'll put it on (for example yoursite.com). The embed only loads on domains in that list, so add every site you plan to use it on.

Step 2: Open its settings

Open the wall's settings. Leave the layout on List View, the default. Set the display limit to how many earthquakes you want on screen at once. Our demo shows up to 30.

Step 3: Turn on the External API Data Source

Scroll to External API Data Source and tick Enable. Then, under "Start from a preset", click USGS Earthquakes (GeoJSON). That fills in every field below. Here's what each one does, so you can change it later:

  • API URL: the feed above.
  • Items Path: features. This tells VitalWall where the list of earthquakes sits, so each earthquake becomes one row.
  • Label Field: properties.place. The text on each row.
  • Value Field: properties.mag. The number in the circle.
  • Group/Category Field: properties.type. The USGS event type, such as "earthquake".
  • ID Field: id. USGS's own ID for each earthquake, so each row keeps the same ID from one refresh to the next.
  • Refresh Interval: 1 minute. The slider goes from 30 seconds to 10 minutes. USGS updates this feed every minute, so faster won't show you more.
  • Attribution: "Earthquake data courtesy of the U.S. Geological Survey (USGS)", linked to earthquake.usgs.gov.
  • Sort Items: the preset picks "By value, highest first", so the biggest earthquake sits on top. Our demo uses "As returned by the API" instead, which keeps the USGS order, newest first. Pick whichever fits your screen.
  • Display Template: Metric, with 1 decimal place. Metric draws the value in a large colored circle. The preset's color scale goes green below 5, yellow from 5 to 6, orange from 6 to 7 and red from 7 up. Our demo uses its own shades, so its circles won't match those ranges exactly. Change the ranges or colors to match your site.

One extra field we added on our demo: Subtitle Field set to properties.alert. USGS fills that in for some earthquakes and leaves it empty for most, so only those rows get a second line. That's the "green" you see under the Indonesia row in the screenshot.

Step 4: Test it before you save

Click Test & Fetch Sample. The editor calls the feed right there and shows you sample rows built from your settings, plus the field paths it found in the first earthquake. If a row looks wrong, you can pick a different path from that list instead of guessing.

When the sample looks right, click Save Changes, then View Wall to see it live.

Step 5: Put it on your site

Paste this where you want the wall, with your wall's ID:

<!-- 1. Add the VitalWall script once, anywhere on the page --> <script type="module" src="https://vitalwall.com/v1/vitalwall.js"></script> <!-- 2. Show your wall where you want it --> <vital-wall wall="YOUR_WALL_ID" layout="list"></vital-wall>

The embed code is the same as for any VitalWall wall. layout="list" matches the wall's default, so you can leave it off. All of the USGS settings stay in the dashboard, and the embed fetches fresh earthquakes on the refresh interval you set. The attribution line doesn't print inside the embed, so credit USGS on your page next to the wall, like our demo does under its list.

For a TV, open the wall's display link on the screen instead. It refreshes on the same interval.

What happens behind the scenes

  • We fetch, not your visitors. VitalWall calls the USGS feed from our servers, never from the viewer's browser, and only while someone has the wall open.
  • One fetch serves many views. The result is cached for about one refresh interval, so a busy page doesn't hammer the feed.
  • Text is escaped. Place names from the feed go into the page as plain text, so a feed can't put its own markup on your wall.

Make it your own

  • Smaller earthquakes: swap the URL for the M2.5+ feed (2.5_day.geojson) or every recorded quake (all_day.geojson). All the summary feeds share the same format, so the field settings stay the same. The busier feeds return a lot of rows, and your display limit decides how many show.
  • Only the big ones: use significant_week.geojson or significant_month.geojson for a quieter wall.
  • A different look: set layout="grid", layout="bubble" or layout="ticker" on the <vital-wall> tag to show the same feed another way. Ticker, Treemap or Map? Picking the Right Live Wall Layout walks through each one.
  • Your colors: change the color scale in the display template, or style the whole wall with custom CSS in its settings.

See it running

Watch the real thing on our live earthquakes demo. The same recipe works for any public JSON feed: change the URL, the items path and two field names.

Want to see your own data move? Start free on VitalWall. No credit card needed.

Related Posts