Weather station scripts - USGS earthquakes

They're free, but use at your own risk

The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

Many of these scripts are now available on GitHub at

If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

This page was updated Tuesday, 30-Jun-2020 9:12 AM

PHP Scripts (run on webserver)

Recent nearby earthquakes (from USGS, NRC, BGS) PHP

Here in California, we're a bit sensitive to the earth moving (it happens a lot), so I wrote a PHP scripts to get, cache and reformat the last 7 days of earthquake information so it can be included on the website with links to additional info.

The output of these scripts is XHTML 1.0-Strict compliant. All of them use the same style for inclusion into your webpage as shown in the example below.

Note: Version 2.00 of the script replaced Google maps with Leaflet/OpenStreetMaps scripts, so you no longer need a Google API key (or any API key to use the 5 included maps with the script.
Version 3.00 adds two additional (free) maps: NatGeo and Delorme(Garmin) options. Also tectonic plates and/or faults can be displayed on the map. See the settings below for the geographical areas covered by the fault maps.

If you wish to use the OPTIONAL tiles (terrain3, Satellite maps), you will need a API key (called an "Access Token") which can be acquired (for free with 50K accesses usage/month) at:

in the quakes.php script you can put

$setMapboxAPIkey = '-replace-this-with-your-API-key-here-';

Note: if using the Saratoga template set, put a new entry in Settings.php

$SITE['mapboxAPIkey'] = '-replace-this-with-your-API-key-here-';

A Mapbox API key is OPTIONAL .. you do not need it to use maps from 5 included free map tile providers.

The USA/World earthquake script uses the new USGS GeoJSON feed for data and provides information on USA quakes of 1.0+ magnitude and Worldwide quakes of 4.0+ magnitude. This script is included in the AJAX/PHP Base-USA and Base-World template sets. Sample output with USA settings:

Earthquakes in the past 7 days of magnitude 2.0 or greater within 200 mi
Update time = Sun, 05-Jul-2020 6:45pm PDT

Epicenter Near Magnitude Distance to Epicenter Time Link
1 mi ESE of The Geysers, CA 2.1 000178111 mi 1593994384Sun, 05-Jul-2020 5:13pm PDT map
2 mi N of Pinnacles, CA 2.1 00011169 mi 1593979789Sun, 05-Jul-2020 1:09pm PDT map
1 mi NW of The Geysers, CA 4.0 000180112 mi 1593965647Sun, 05-Jul-2020 9:14am PDT map
9 mi SW of Lakeport, CA 2.2 000206128 mi 1593921865Sat, 04-Jul-2020 9:04pm PDT map
3 mi N of Pinnacles, CA 2.2 00011069 mi 1593908451Sat, 04-Jul-2020 5:20pm PDT map
11 mi NW of Pinnacles, CA 2.3 00009760 mi 1593907469Sat, 04-Jul-2020 5:04pm PDT map
19 mi SE of Bodie, CA 3.2 000302188 mi 1593893377Sat, 04-Jul-2020 1:09pm PDT map
2 mi NNE of Hamilton City, CA 2.3 000278173 mi 1593886689Sat, 04-Jul-2020 11:18am PDT map
17 mi ESE of Bodie, CA 2.4 000302188 mi 1593877801Sat, 04-Jul-2020 8:50am PDT map
1 mi SW of Ridgemark, CA 2.1 00007848 mi 1593837862Fri, 03-Jul-2020 9:44pm PDT map
12 mi SSW of Bootjack, CA 2.2 000180112 mi 1593835524Fri, 03-Jul-2020 9:05pm PDT map
14 mi SE of Bodie, CA 2.0 000293182 mi 1593817079Fri, 03-Jul-2020 3:57pm PDT map
16 mi SE of Bodie, CA 2.9 000295183 mi 1593814973Fri, 03-Jul-2020 3:22pm PDT map
14 mi ENE of San Ardo, CA 2.1 000179111 mi 1593814276Fri, 03-Jul-2020 3:11pm PDT map
6 mi SW of Brentwood, CA 2.1 00006943 mi 1593804276Fri, 03-Jul-2020 12:24pm PDT map
16 mi SE of Bodie, CA 2.5 000295183 mi 1593800568Fri, 03-Jul-2020 11:22am PDT map
18 mi SE of Bodie, CA 2.6 000299186 mi 1593792828Fri, 03-Jul-2020 9:13am PDT map
14 mi SE of Pinnacles, CA 2.1 00013685 mi 1593754593Thu, 02-Jul-2020 10:36pm PDT map
10 mi SSE of Tres Pinos, CA 2.7 00009660 mi 1593752232Thu, 02-Jul-2020 9:57pm PDT map
4 mi NE of Pinnacles, CA 2.1 00011471 mi 1593743645Thu, 02-Jul-2020 7:34pm PDT map
4 mi E of Tres Pinos, CA 2.1 00008754 mi 1593732604Thu, 02-Jul-2020 4:30pm PDT map
4 mi SE of Talmage, CA 2.5 000222138 mi 1593726333Thu, 02-Jul-2020 2:45pm PDT map
7 mi SSW of Toms Place, CA 3.4 000292181 mi 1593715781Thu, 02-Jul-2020 11:49am PDT map
7 mi SSW of Toms Place, CA 2.1 000292181 mi 1593712571Thu, 02-Jul-2020 10:56am PDT map
7 mi SSW of Toms Place, CA 2.7 000292181 mi 1593706369Thu, 02-Jul-2020 9:12am PDT map
7 mi S of Yosemite Lakes, CA 2.0 000201125 mi 1593700433Thu, 02-Jul-2020 7:33am PDT map
6 mi SSW of Tres Pinos, CA 2.4 00008452 mi 1593691297Thu, 02-Jul-2020 5:01am PDT map
4 mi SSW of Ridgemark, CA 2.2 00007949 mi 1593683256Thu, 02-Jul-2020 2:47am PDT map
1 mi SW of Ridgemark, CA 2.7 00007848 mi 1593662564Wed, 01-Jul-2020 9:02pm PDT map
12 mi E of Markleeville, CA 2.3 000266165 mi 1593657960Wed, 01-Jul-2020 7:46pm PDT map
18 mi SE of Bodie, CA 2.4 000301187 mi 1593651143Wed, 01-Jul-2020 5:52pm PDT map
5 mi WSW of Penn Valley, CA 2.3 000220137 mi 1593650773Wed, 01-Jul-2020 5:46pm PDT map
4 mi W of Cape Vizcaino, CA 2.6 000318198 mi 1593645222Wed, 01-Jul-2020 4:13pm PDT map
18 mi SE of Bodie, CA 2.1 000299186 mi 1593624395Wed, 01-Jul-2020 10:26am PDT map
4 mi W of Yosemite Lakes, CA 2.0 000193120 mi 1593596888Wed, 01-Jul-2020 2:48am PDT map
18 mi SE of Bodie, CA 2.2 000300187 mi 1593575978Tue, 30-Jun-2020 8:59pm PDT map
10 mi WNW of Lake Nacimiento, CA 2.4 000186116 mi 1593420314Mon, 29-Jun-2020 1:45am PDT map
11 mi NNE of Nice, CA 2.3 000229142 mi 1593418743Mon, 29-Jun-2020 1:19am PDT map

38 earthquakes found. Click on location or map links for more details from the USGS

Script by

This was invoked by using the following code:

# settings -------------------------- 
  $doIncludeQuake = true;
# uncomment ONE of the $setDistanceDisplay lines to use as template for distance displays  
#  $setDistanceDisplay = 'mi (km)';
  $setDistanceDisplay = 'mi';
#  $setDistanceDisplay = 'km (mi)';
#  $setDistanceDisplay = 'km';

  $setDistanceRadius  = 1000;  // same units as first unit in $setDistanceDisplay
# NOTE: quakes of magnitude 1.0+ are available for USA locations only.
#    non-USA location earthquakes of magnitude 4.0+ are the only ones available from the USGS
  $setMinMagnitude = '2.0';  // minimum Richter Magnitude to display
  $setHighMagnitude = '4.0';  // highlight this Magnitude and greater
# script will use your $SITE[] values for latitude, longitude, cityname, timezone and time display format
# but you can override them if you with with the commented statements below:
  $setLatitude  = 37.2746251;    //North=positive, South=negative decimal degrees
  $setLongitude = -122.0229656;   //East=positive, West=negative decimal degrees
# The above settings are for location
#  $setLocationName = 'Saratoga, CA'; // city/town name for lat/long above 
  $setTimeZone = "America/Los_Angeles";  //NOTE: this *MUST* be set correctly to
# translate UTC times to your LOCAL time for the displays.
# Use to find the timezone suitable for
#  your location.

#  pick a format for the time to display ..uncomment one (or make your own)
 $setTimeFormat = 'D, Y-m-d H:i:s T';  // Fri, 2006-03-31 14:03:22 TZone
#  $setTimeFormat = 'D, d-M-Y H:i:s T';  // Fri, 31-Mar-2006 14:03:22 TZone

  $setDoLinkTarget = false;   // =true; to have links open in new page, =false; for XHTML 1.0-Strict

	$setMapProvider = 'Esri_WorldTopoMap'; // ESRI topo map - no key needed
# $setMapProvider = 'OSM';     // OpenStreetMap - no key needed
# $setMapProvider = 'Terrain'; // Terrain map by - no key needed
# $setMapProvider = 'OpenTopo'; // - no key needed
# $setMapProvider = 'Wikimedia'; // Wikimedia map - no key needed
# $setMapProvider = 'NatGeo';  // National Geographic world map -no key needed  
# $setMapProvider = 'Delorme';  // Garmin world map -no key needed  
# $mapProvider = 'MapboxSat';  // Map by - API KEY needed in $setMapboxAPIkey 
# $mapProvider = 'MapboxTer';  // Map by - API KEY needed in $setMapboxAPIkey 
 $setMapboxAPIkey = '--mapbox-API-key--';  // use this for the API key to MapBox
# for fault displays
 $setFaultDisplay = 'USGS'; // ='' for none, see below for more choices
# Note: not all fault displays have entries for all countries. You'll need to choose the one that
#   displays the information for your geography.
# 'PH' covers the Phillipines only
# 'USGS' covers the lower-48 CONUS states only but with fault types/names/ages
# 'USGS2' covers all 50 US states, but with only small/medium/large fault types (no descriptions)
# 'USGS3' covers the mostly western CONUS lower-48 states only  with fault names and types only
# 'GEM' covers much of the world (omitting Canada, Scandanavia and UK/Ireland)
# 'WORLD' covers most of the world with 4 fault types (  rift, step, tectonic contact, thrust-fault)
# 'BGS' convers the UK (England, Wales, Scotland, Northern Ireland) 

 $setPlateDisplay = true;  // =true; show tectonic plates ; =false; suppress tectonic plate display


Also required is the styling and JavaScript <script> statements in the <head>...</head> part of the page (see the sample quakes.php page in the distribution package for details).

The USGS GeoJSON earthquake script (V3.03 - 30-Jun-2020):
download .zip package [ see version history ]

This script loads the GeoJSON feed for all earthquakes in the last 7 days from the USGS. For the USA, magnitude 1.0+ quakes are available. For non-USA locations, the USGS only provides information on magnitude 4.0+ based on the data they receive from partner seismographic organizations. If you are installing the script for standalone use, do download the .ZIP package as it contains the graphics files needed for the Google Map. If you are using the AJAX/PHP template set (V3+), the script is already integrated into the Base-Canada, Base-USA, and Base-World templates.

For Base-World template users, the script is compatible with the language translation features of the template set. You may need to add to your language-LL.txt translation file the following entries (translated) in order to show the ouput in language LL.
Note: the |of| entry below is used in the reports for quake location as in:
  20 mi NNW of Saratoga, California

langlookup|Update time|Update time|
langlookup|No earthquakes of magnitude|No earthquakes of magnitude|
langlookup|or greater within|or greater within|
langlookup|reported in last 7 days|reported in last 7 days|
langlookup|Cluster - click to expand details|Cluster - click to expand details|
langlookup|Enable JavaScript to view the Google Map.|Enable JavaScript to view the Google Map.|
langlookup|Earthquakes in the past 7 days of magnitude|Earthquakes in the past 7 days of magnitude|
langlookup|or greater within|or greater within|
langlookup|Epicenter Near|Epicenter Near|
langlookup|Distance to Epicenter|Distance to Epicenter|
langlookup|Note: Click on column heading marked with|Note: Click on column heading marked with|
langlookup|to sort column contents.|to sort column contents.|
langlookup|earthquakes found. Click on location or map links for more details from the <a href="">USGS</a>|earthquakes found. Click on location or map links for more details from the <a href="">USGS</a>|
langlookup|Distance to epicenter|Distance to epicenter|
langlookup|Map and data courtesy of|Map and data courtesy of|
langlookup|United States Geological Survey|United States Geological Survey|

The Canada earthquake script : demo and download [ see version history ]
Documentation on how to customize the script is in comments contained in the source. For anywhere in Canada, you just have to change $myLat and $myLong to your station's decimal latitude and longitude to see it work in your area. Defaults are for magnitude 2.0 (or greater) within a 500 km radius. This script uses data from Natural Resources Canada website and returns earthquake activity over the last 30 days. Version 1.03+ now provides both English and French display.

The UK earthquake script : demo and download [ see version history ]
Documentation on how to customize the script is in comments contained in the source. For anywhere in the United Kingdom, you just have to change $myLat and $myLong to your station's decimal latitude and longitude to see it work in your area. Defaults are for earthquakes within a 500 km radius. This script uses data from British Geological Survey website and returns earthquake activity over the last 30 days.
BGS data is used with permission as long as the attribution built into the script displays with the script output.

Deprecated Scripts

With the release of quake-json.php script on 8-Sep-2012, the following scripts are no longer maintained as the USGS is deprecating the pages on their website that these scripts require:

  • quake-CANV.php
  • quake-USA.php
  • quake-WORLD.php and quake-WORLD-ML.php

The quake-json.php script uses the USGS new GeoJSON feed for 1+ (USA) and 4+ (World) magnitude events and replaces the functionality of the above scripts.