Search code examples
javascriptgetlocation

Why does the first parameter in getLocation doesn't execute as a function?


How can I execute the function accept in updatePosition ? Why can denyexecute itself but not accept ?

 accept = alert(123);
 deny = alert(123);

 function getLocation(accept,deny) { 
    
    if (navigator.geolocation) {     
        navigator.geolocation.getCurrentPosition(function (position) {
            updatePosition(position, accept);
        }, deny);
    } else {
      deny;
    }

  }

  function updatePosition(position, accept) {
    PositionLat = position.coords.latitude;
    PositionLon = position.coords.longitude;    
    accept;

  }

Solution

  • How can I execute the function accept in updatePosition ?

    Put () after the name.

    Why can denyexecute itself

    It can't. You are passing deny as an argument to navigator.geolocation.getCurrentPosition. The code in navigator.geolocation.getCurrentPosition calls it.