0

i am trying to paas value from

getLocation(1);


function getLocation(a) {
        
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition(a));
      } else {
        alert("Try any other browser");
      }
      
    }
    
    function showPosition(a,position) {
        if (a == 1){
        $('[name="location_url_ot"]').val(position.coords.latitude+','+position.coords.longitude);
        }
    }

but function showPosition doesnot accept a any suggestion?

  • `getCurrentPosition` should accept a callback function. Currently, you're passing it the return value of calling `showPosition()`. You can [curry the arguments](https://stackoverflow.com/questions/36314/what-is-currying) of `showPosition` which would allow you to pass in `a`, while also getting a function as the return value to pass into `getCurrentPosition`. – Nick Parsons Oct 27 '20 at 15:31
  • getLocation is not defined –  Oct 27 '20 at 15:31
  • actually i am using a same function to pass value in 2 different input filed one call by getlocation(); and 2nd is getlocation(1); –  Oct 27 '20 at 15:33
  • `navigator.geolocation.getCurrentPosition( function(position) { showPosition(a, position); });` – epascarello Oct 27 '20 at 15:36

1 Answers1

0

Try this

function showPosition(a) {
  return (position) => {
    if (a === 1) {
      $('[name="location_url_ot"]').val(position.coords.latitude + ',' + position.coords.longitude);
    }
  };
}
ttquang1063750
  • 803
  • 6
  • 15
  • position is must required –  Oct 27 '20 at 15:37
  • 1
    from above, we provide two functions: outer takes `a` param and inner takes `position` param. ex: `showPosition(1)({coords: {latitude: number, longitude: number}})` – ttquang1063750 Oct 27 '20 at 15:41