Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (25 sloc) 815 Bytes
This function will be able to get the current location
<html>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function getLocation(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPostion(savePostion, postionError, {timeout:10000});
}
else{
//geolocation is not supported by the browser
}
}
function positionError(error){
var errorCode = error.code;
var message = error.message;
alert(message);
}
function savePosition(position){
$_post("geolocation.php", {lat: postion.coords.latitude, lng: position.coords.longitude});
}
</script>
<body>
<button onclick= "getLocation(); "> Current Location</button>
</body>
</html>
You can’t perform that action at this time.