I am trying to use geolocation in javascript. However, on my console i see an error which is: ReferenceError: success is not defined
. As a result i am unable my code is unable to execute the rest of the function. Here is my implementation:
function clicked(){
console.log("inside clicked");
if($("#checkbox-h-2j").prop('checked')){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(success,error);
}
else{
document.getElementById("hello").innerHTML = "Not supported";
}
function success(position){
lat = position.coords.latitude;
lng = position.coords.longitude;
document.getElementById("hello").innerHTML = "lat :"+lat+"<br>long :"+lng;
}
function error(err){
document.getElementById("hello").innerHTML = "Error Code: "+error.code;
if(err.code == 1){
document.getElementById("hello").innerHTML = "Access denied";
}
if(err.code == 2){
document.getElementById("hello").innerHTML = "Position unavailable";
}
}
}}