-
震中经度:
-
震中纬度:
-
震级:
-
震源深度:
-
发生时间:
javascript
// script.js// 获取地震数据
async function getEarthquakeData() {const response = await fetch('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson');const data = await response.json();return data;
}// 查找最近发生在成都的地震
async function findChengduEarthquake(data) {const chengduEarthquakes = data.features.filter(earthquake => {return earthquake.properties.place.includes('Chengdu');});return chengduEarthquakes[0];
}// 更新页面上的数据
function updateData(earthquake) {const longitude = document.getElementById('longitude');const latitude = document.getElementById('latitude');const magnitude = document.getElementById('magnitude');const depth = document.getElementById('depth');const time = document.getElementById('time');longitude.innerHTML = earthquake.geometry.coordinates[0];latitude.innerHTML = earthquake.geometry.coordinates[1];magnitude.innerHTML = earthquake.properties.mag;depth.innerHTML = earthquake.geometry.coordinates[2];time.innerHTML = new Date(earthquake.properties.time).toLocaleString();
}// 初始化地图
function initMap() {const map = new google.maps.Map(document.getElementById('map'), {center: { lat: 30.667, lng: 104.067 },zoom: 10});
}// 主函数
async function main() {const data = await getEarthquakeData();const earthquake = await findChengduEarthquake(data);updateData(earthquake);initMap();
}main();