I have js code which gets which gets users lat long but the problem is when I call the js function in my asp.net control button it does not work and no alert is shown and the function getLocation does not work
var x = document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition, showError); } else { x.innerHTML = "Geolocation is not supported by this browser."; } }
function showPosition(position) {
// var latlondata = position.coords.latitude + "," +position.coords.longitude;
var latlon = position.coords.latitude;
alert(latlon)
document.getElementById('<%=abc123.ClientID%>').innerText = latlon;
}
function showError(error) {
if (error.code == 1) {
x.innerHTML = "User denied the request for Geolocation."
}
else if (err.code == 2) {
x.innerHTML = "Location information is unavailable."
}
else if (err.code == 3) {
x.innerHTML = "The request to get user location timed out."
}
else {
x.innerHTML = "An unknown error occurred."
}
}
and here is my control code
<asp:Label ID="abc123" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="getLocation()" OnClick="Button1_Click " />