earthquake.usgs.gov API возвращает полезную нагрузку в формате GeoJSON
. Есть библиотека geogson
, которая реализует все необходимые адаптеры. Вам нужно только добавить зависимость:
<dependency>
<groupId>com.github.filosganga</groupId>
<artifactId>geogson-core</artifactId>
<version>1.2.21</version>
</dependency>
и ниже вы можете найти простой пример, как его использовать:
import com.github.filosganga.geogson.gson.GeometryAdapterFactory;
import com.github.filosganga.geogson.model.FeatureCollection;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class GsonApp {
public static void main(String[] args) throws Exception {
URL url = new URL("https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&eventtype=earthquake");
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(new GeometryAdapterFactory())
.create();
FeatureCollection collection = gson.fromJson(in, FeatureCollection.class);
collection.features().forEach(f -> {
System.out.println(f.properties());
});
}
}
Над отпечатками приложений:
null, cdi=null, url="https://earthquake.usgs.gov/earthquakes/eventpage/us1000jimv", ids=",us1000jimv,", time=1552230050190, detail="https://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us1000jimv&format=geojson", updated=1553025676040, status="reviewed"}
{dmin=0.01354, code="73150236", sources=",nc,", tz=-480, mmi=null, type="earthquake", title="M 0.3 - 8km WNW of Cobb, CA", magType="md", nst=10, sig=2, tsunami=0, mag=0.32, alert=null, gap=159, rms=0.02, place="8km WNW of Cobb, CA", net="nc", types=",geoserve,nearby-cities,origin,phase-data,scitech-link,", felt=null, cdi=null, url="https://earthquake.usgs.gov/earthquakes/eventpage/nc73150236", ids=",nc73150236,", time=1552229803430, detail="https://earthquake.usgs.gov/fdsnws/event/1/query?eventid=nc73150236&format=geojson", updated=1552436044263, status="reviewed"}
{dmin=0.0134, code="73150231", sources=",nc,", tz=-480, mmi=null, type="earthquake", title="M 0.6 - 8km WNW of Cobb, CA", magType="md", nst=9, sig=5, tsunami=0, mag=0.57, alert=null, gap=152, rms=0.01, place="8km WNW of Cobb, CA", net="nc", types=",geoserve,nearby-cities,origin,phase-data,scitech-link,", felt=null, cdi=null, url="https://earthquake.usgs.gov/earthquakes/eventpage/nc73150231", ids=",nc73150231,", time=1552229731210, detail="https://earthquake.usgs.gov/fdsnws/event/1/query?eventid=nc73150231&format=geojson", updated=1552235523281, status="automatic"}
....