screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [ipAddress, setIpAddress] = useState('49.36.213.0'); const [locationData, setLocationData] = useState({}); const [latitude, setLatitude] = useState(''); const [longitude, setLongitude] = useState(''); const fetchLocationInfo = () => { axios.get(`https://ipapi.co/${ipAddress}/json`) .then((response) => { setLocationData(response.data); // Set latitude and longitude from the response setLatitude(response.data.latitude); setLongitude(response.data.longitude); }) .catch((error) => { console.error('Error fetching location data:', error); }); }; return ( <div className='container'> <h2 className='title'>React Js Get Location Information by IP Address</h2> <div className='input-container'> <label className='label'>Enter IP Address:</label> <input type="text" className='input' value={ipAddress} onChange={(e) => setIpAddress(e.target.value)} /> <button className='button' onClick={fetchLocationInfo}>Get Location</button> </div> <br /> <h3 className='subtitle'>Location Information</h3> <ul className='location-info'> <li className='location-item'>IP Address: {locationData.ip}</li> <li className='location-item'>City: {locationData.city}</li> <li className='location-item'>Region: {locationData.region}</li> <li className='location-item'>Country: {locationData.country}</li> <li className='location-item'>Latitude: {latitude}</li> <li className='location-item'>Longitude: {longitude}</li> </ul> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { font-family: Arial, sans-serif; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); max-width: 600px; margin: 0 auto; text-align: center; } .title { font-size: 24px; margin-bottom: 20px; color: #333; } .input-container { display: flex; flex-direction: row; } .label { font-size: 18px; margin-bottom: 10px; color: #333; } .input { padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; outline: none; } .button { padding: 10px 20px; font-size: 16px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } .button:hover { background-color: #0056b3; } .subtitle { font-size: 20px; margin-top: 20px; margin-bottom: 10px; color: #333; } .location-info { list-style: none; padding: 0; } .location-item { font-size: 16px; margin-bottom: 5px; color: #333; } </style> </body> </html>