Welcome aboard! We are happy you are here and wish you good net-raft!
<!DOCTYPE html>
<html>
<body>
<button onclick="getLocation()">Get</button>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
document.write ("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
document.write ("Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
function YourPosition(myposition)
{
var lat1 = myposition.coords.latitude;
var lng1 = myposition.coords.longitude;
document.write (lat1 + " , " + lng1)
}
if(navigator.geolocation)
navigator.geolocation.getCurrentPosition(YourPosition);
else
alert("something was wrong");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<button onclick="getmyLocation()">click</button>
<p id="test"></p>
<script>
var x = document.getElementById("test");
function getmyLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showing_position, showing_error);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showing_position(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
function showing_error(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
</script>
</body>
</html>
The most helpful JAVASCRIPT solutions
How can I get the last day and the next day in javascript ?JAVASCRIPT
Click to see more ...
6.3K
508
How to get client machine name or computer name with javascript ?JAVASCRIPT
Click to see more ...
30.9K
396
get client hostname javascriptJAVASCRIPT
Click to see more ...
5.6K
301
create 3d barrel using javascriptJAVASCRIPT
Click to see more ...
4.3K
258
Create fireworks using javascriptJAVASCRIPT
Click to see more ...
4K
204
create qr code javascriptJAVASCRIPT
Click to see more ...
3.4K
205
detect ie javascriptJAVASCRIPT
Click to see more ...
3.5K
194
fire event when user is idle javascriptJAVASCRIPT
Click to see more ...
3.3K
186
how to create foreach class using javascript ?JAVASCRIPT
Click to see more ...
3K
184
create earth in universe with three.jsJAVASCRIPT
Click to see more ...
3.6K
185