This web application allows users to fetch and display their current location (latitude and longitude) and, optionally, their IPv4 address. It provides a simple and intuitive interface for users to interact with.
-
Fetch Location: Users can click the "Display Location" button to retrieve their current latitude and longitude coordinates using the browser's geolocation API.
-
Fetch Location and IP: Users can also click the "Display IP With Location" button to fetch both their location and IPv4 address. The IPv4 address is obtained using WebRTC technology.
-
Clear Information: The application provides a "Clear" button to reset and clear all displayed information.
-
HTML: Markup language for structuring the webpage.
-
CSS: Stylesheet language for styling the webpage elements.
-
JavaScript: Programming language for adding interactivity to the webpage.
The JavaScript code in this project primarily handles fetching the user's location and IPv4 address and updating the webpage accordingly. Here's a detailed explanation of its functionality:
When the "Display Location" button is clicked, the code checks if the browser supports geolocation. If supported, it uses the navigator.geolocation.getCurrentPosition()
method to get the user's current position (latitude and longitude). The retrieved coordinates are then displayed on the webpage.
When the "Display IP With Location" button is clicked, the code first fetches the user's location similar to the previous scenario. Additionally, it utilizes WebRTC (Web Real-Time Communication) to obtain the user's IPv4 address.
Here's how WebRTC is working to fetch the IPv4 address:
- A new
RTCPeerConnection
object is created. - An ICE (Interactive Connectivity Establishment) candidate is generated by calling
pc.createDataChannel("")
andpc.createOffer()
. This triggers the gathering of network information including the local IP address. - The
pc.onicecandidate
event is triggered when an ICE candidate is found. - The IPv4 address is extracted from the ICE candidate information and displayed on the webpage along with the location.
The "Clear" button resets and clears all displayed information (latitude, longitude, and IPv4 address) from the webpage.
This project was created by Pabitra Banerjee. You can contact Pabitra Banerjee via rockstarpabitra2204@gmail.com for any inquiries or contributions.
[Location And IP Display Web Application] (https://pabitrabanerjee.me/Location-And-IP-Display-Web-Application)