JSFiddle - React, Tailwind, and code Playground
HTML
<p>Running test...</p>
JavaScript
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {
maximumAge: 0
});
$('body').append("<p>geoLocation is supported by this browser</p>");
} else {
$('body').append("<p>geoLocation is NOT supported by this browser</p>");
}
function successCallback(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$('body').append("<p>Your location is: " + latitude + "," + longitude);
}
function errorCallback(error) {
var msg = "<p>Can't get your location. Error = ";
if (error.code == 1)
msg += "PERMISSION_DENIED";
else if (error.code == 2)
msg += "POSITION_UNAVAILABLE";
else if (error.code == 3)
msg += "TIMEOUT";
msg += ", msg = "+error.message;
$('body').append(msg);
}