<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function getLocation() {
if (navigator.geolocation) {
//set timeout at 60000 milliseconds (60 seconds)
var options = { timeout: 60000 };
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
} else {
alert("Browser does not support geolocation!");
}
}
function successCallback(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("Latitude : " + latitude + " Longitude: " + longitude);
};
function errorCallback(err) {
if (err.code == 1) {
alert("Error: Access is denied!");
} else if (err.code == 2) {
alert("Error: Position is unavailable!");
} else if (err.code == 3) {
alert("Error: Geolocation attempt timed out!");
} else {
alert("Error: Geolocation failed due to unknown error!");
}
}
//window.onload = getLocation();
</script>
</head>
<body>
<form id="form1" runat="server">
<button type="button" onclick="getLocation();">Get Location</button>
</form>
</body>
</html>
No comments:
Post a Comment