0

I tried to keep this in a loop but webpage freezes every time I try to keep this in the loop. Any suggestion how to get location live update by this?

function hello(){
   for(var i=0;i<=10;i++){  
      if(i==10){
         call();
         i=0;
     }
}

function call(){
  var settings = {
    "url": "https://pos.ls.hereapi.com/positioning/v1/locate?apiKey=imnotgoingtoshareliveapikeyeveragain",
    "method": "POST",
    "timeout": 0,
    "headers": {
      "Content-Type": "application/json"
    },
    "data": JSON.stringify({"lte":[{"mcc":404,"mnc":49,"cid":231706401}]}),
  };

  $.ajax(settings).done(function (response) {
    console.log(response);
  });
}
4
  • can you post your loop? code Commented Dec 24, 2019 at 10:43
  • Whenever do you need to execute call() function? Commented Dec 24, 2019 at 10:48
  • location frequency say every 10sec! @AhedKabalan Commented Dec 24, 2019 at 10:50
  • I suggest regenerating the API key and not posting a live API keys inside questions ;) Commented Dec 24, 2019 at 11:38

2 Answers 2

1

Try this one (every 10 seconds will trigger call function):

function call(){
    var settings = {
      "url": "https://pos.ls.hereapi.com/positioning/v1/locate?apiKey=s_WF6U2g60ucHbmnYIyuieeUWnkT0jshGf4mD33kpwI",
      "method": "POST",
      "timeout": 0,
      "headers": {
        "Content-Type": "application/json"
      },
      "data": JSON.stringify({"lte":[{"mcc":404,"mnc":49,"cid":231706401}]}),
    };

    $.ajax(settings).done(function (response) {
      console.log(response);
    });
  }

  function hello(){
     setInterval(function(){ call() }, 10000);
  };

  hello();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

Comments

0

Instead of writing two separate functions, you can use setInterval to run every x seconds:

var settings = {
    "url": "https://pos.ls.hereapi.com/positioning/v1/locate?apiKey=s_WF6U2g60ucHbmnYIyuieeUWnkT0jshGf4mD33kpwI",
    "method": "POST",
    "timeout": 0,
    "headers": {
      "Content-Type": "application/json"
    },
    "data": JSON.stringify({"lte":[{"mcc":404,"mnc":49,"cid":231706401}]}),
  };

setInterval(function(){ 


 $.ajax(settings).done(function (response) {
    console.log(response);
  });



 }, 10000);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.