CSS:
css
body {font-family: Arial, sans-serif;font-size: 16px;
}h1 {margin-top: 0;
}form {margin-top: 10px;
}label {display: inline-block;width: 100px;
}input {width: 300px;
}results {margin-top: 10px;
}.result {border: 1px solid black;padding: 10px;margin-bottom: 10px;
}PHP:
php
';
foreach ($chargingStations as $station) {echo '
' . $station['name'] . '
';echo '
地址: ' . $station['address'] . '
';echo '
距离: ' . $station['distance'] . '
';
}
echo '';// 获取最近充电桩的函数
function getChargingStations($address) {// 使用 Google Places API 获取附近充电桩$url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=' . $address . '&radius=5000&type=ev_charging_station&key=API_KEY';$response = file_get_contents($url);$data = json_decode($response, true);// 解析结果并返回最近充电桩的数组$stations = array();foreach ($data['results'] as $result) {$stations[] = array('name' => $result['name'],'address' => $result['vicinity'],'distance' => $result['distance']);}// 按距离对数组排序usort($stations, function($a, $b) {return $a['distance'] - $b['distance'];});return $stations;
}
?>