Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Starting point for visualization project - read earthquake data from the USGS geojson data feed.
/* Example of reading earthquake data from the USGS data feed.
Starting point for visualization project.
This script requests GEOJson formatted data, then parses it and prints some of the information.
It requires the JSONObject class for Unity, which can be downloaded from
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class readQuakes : MonoBehaviour
public string url = "";
void Start()
IEnumerator GetData(string url)
Debug.Log($"sending request {url}");
UnityWebRequest req = UnityWebRequest.Get(url);
yield return req.SendWebRequest();
if (req.isNetworkError)
Debug.Log($"Error ({url}): {req.error}");
JSONObject data = new JSONObject(req.downloadHandler.text, -2, false, false);
for (int i=0; i < data["metadata"]["count"].n; i++)
float lat = data["features"][i]["geometry"]["coordinates"][1].n;
float lon = data["features"][i]["geometry"]["coordinates"][0].n;
float mag = data["features"][i]["properties"]["mag"].n;
Debug.Log($"lat: {lat} lon: {lon} mag: {mag}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.