Why navigator.geolocation.watchposition not work in setInterval()? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceReact-Native 0.20 - setInterval not working as expectedHow do I get the json nested object?Retrying Geolocation after error in React Nativenavigator.geolocation.watchPosition not working correctly on ios deviceReact Native + Fetch => TypeError: Cannot read property 'then' of undefinedReact-Native, Firebase and some Reloads, login stops workingreact native can't find location from cellular networkUnable to use setState in react componentProblem while using getCurrentPosition geoLocation function within setInterval method for getting user current position with React-Native

Why are PDP-7-style microprogrammed instructions out of vogue?

Nested ellipses in tikzpicture: Chomsky hierarchy

What can I do if neighbor is blocking my solar panels intentionally?

What information about me do stores get via my credit card?

Am I ethically obligated to go into work on an off day if the reason is sudden?

Why can't devices on different VLANs, but on the same subnet, communicate?

Drawing vertical/oblique lines in Metrical tree (tikz-qtree, tipa)

Is every episode of "Where are my Pants?" identical?

Can I visit the Trinity College (Cambridge) library and see some of their rare books

Using dividends to reduce short term capital gains?

What's the point in a preamp?

Would an alien lifeform be able to achieve space travel if lacking in vision?

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Why doesn't a hydraulic lever violate conservation of energy?

should truth entail possible truth

Simulating Exploding Dice

Store Dynamic-accessible hidden metadata in a cell

Mortgage adviser recommends a longer term than necessary combined with overpayments

Is an up-to-date browser secure on an out-of-date OS?

Can we generate random numbers using irrational numbers like π and e?

Word to describe a time interval

How did passengers keep warm on sail ships?

Why did Peik Lin say, "I'm not an animal"?

Are spiders unable to hurt humans, especially very small spiders?



Why navigator.geolocation.watchposition not work in setInterval()?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceReact-Native 0.20 - setInterval not working as expectedHow do I get the json nested object?Retrying Geolocation after error in React Nativenavigator.geolocation.watchPosition not working correctly on ios deviceReact Native + Fetch => TypeError: Cannot read property 'then' of undefinedReact-Native, Firebase and some Reloads, login stops workingreact native can't find location from cellular networkUnable to use setState in react componentProblem while using getCurrentPosition geoLocation function within setInterval method for getting user current position with React-Native



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I try to get location coordinate every 1 sec. But geolocation.watchposition not work in setInterval



here is my code:



componentDidMount()
const intervalId = BackgroundTimer.setInterval(() =>
navigator.geolocation.watchPosition((position) =>
console.log(position.coords.latitude);
var lat = parseFloat(position.coords.latitude);
var lng = parseFloat(position.coords.longitude);

console.log("lat :",lat);
console.log("lng :",lng);
);
, 1000);

BackgroundTimer.clearInterval(intervalId);



if I remove BackgroundTimer.setInterval method. It gives me coordinates. But I want everysecond










share|improve this question




























    0















    I try to get location coordinate every 1 sec. But geolocation.watchposition not work in setInterval



    here is my code:



    componentDidMount()
    const intervalId = BackgroundTimer.setInterval(() =>
    navigator.geolocation.watchPosition((position) =>
    console.log(position.coords.latitude);
    var lat = parseFloat(position.coords.latitude);
    var lng = parseFloat(position.coords.longitude);

    console.log("lat :",lat);
    console.log("lng :",lng);
    );
    , 1000);

    BackgroundTimer.clearInterval(intervalId);



    if I remove BackgroundTimer.setInterval method. It gives me coordinates. But I want everysecond










    share|improve this question
























      0












      0








      0








      I try to get location coordinate every 1 sec. But geolocation.watchposition not work in setInterval



      here is my code:



      componentDidMount()
      const intervalId = BackgroundTimer.setInterval(() =>
      navigator.geolocation.watchPosition((position) =>
      console.log(position.coords.latitude);
      var lat = parseFloat(position.coords.latitude);
      var lng = parseFloat(position.coords.longitude);

      console.log("lat :",lat);
      console.log("lng :",lng);
      );
      , 1000);

      BackgroundTimer.clearInterval(intervalId);



      if I remove BackgroundTimer.setInterval method. It gives me coordinates. But I want everysecond










      share|improve this question














      I try to get location coordinate every 1 sec. But geolocation.watchposition not work in setInterval



      here is my code:



      componentDidMount()
      const intervalId = BackgroundTimer.setInterval(() =>
      navigator.geolocation.watchPosition((position) =>
      console.log(position.coords.latitude);
      var lat = parseFloat(position.coords.latitude);
      var lng = parseFloat(position.coords.longitude);

      console.log("lat :",lat);
      console.log("lng :",lng);
      );
      , 1000);

      BackgroundTimer.clearInterval(intervalId);



      if I remove BackgroundTimer.setInterval method. It gives me coordinates. But I want everysecond







      react-native






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 12:15









      hakanhakan

      1709




      1709






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The watchPosition method will automatically call the success callback as soon as the user's position has changed, so doing this won't work. If you really need to get every second (which you might not need as user's position rarely will change in 1 second and it consumes a lot of battery power) you use the setInterval using along with navigator.geolocation.getCurrentPosition method.






          share|improve this answer























          • Actually I want to get location when user change position. But I couldnt handle that

            – hakan
            Mar 8 at 12:35











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063052%2fwhy-navigator-geolocation-watchposition-not-work-in-setinterval%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The watchPosition method will automatically call the success callback as soon as the user's position has changed, so doing this won't work. If you really need to get every second (which you might not need as user's position rarely will change in 1 second and it consumes a lot of battery power) you use the setInterval using along with navigator.geolocation.getCurrentPosition method.






          share|improve this answer























          • Actually I want to get location when user change position. But I couldnt handle that

            – hakan
            Mar 8 at 12:35















          0














          The watchPosition method will automatically call the success callback as soon as the user's position has changed, so doing this won't work. If you really need to get every second (which you might not need as user's position rarely will change in 1 second and it consumes a lot of battery power) you use the setInterval using along with navigator.geolocation.getCurrentPosition method.






          share|improve this answer























          • Actually I want to get location when user change position. But I couldnt handle that

            – hakan
            Mar 8 at 12:35













          0












          0








          0







          The watchPosition method will automatically call the success callback as soon as the user's position has changed, so doing this won't work. If you really need to get every second (which you might not need as user's position rarely will change in 1 second and it consumes a lot of battery power) you use the setInterval using along with navigator.geolocation.getCurrentPosition method.






          share|improve this answer













          The watchPosition method will automatically call the success callback as soon as the user's position has changed, so doing this won't work. If you really need to get every second (which you might not need as user's position rarely will change in 1 second and it consumes a lot of battery power) you use the setInterval using along with navigator.geolocation.getCurrentPosition method.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 12:32









          Vinícius CarraVinícius Carra

          1




          1












          • Actually I want to get location when user change position. But I couldnt handle that

            – hakan
            Mar 8 at 12:35

















          • Actually I want to get location when user change position. But I couldnt handle that

            – hakan
            Mar 8 at 12:35
















          Actually I want to get location when user change position. But I couldnt handle that

          – hakan
          Mar 8 at 12:35





          Actually I want to get location when user change position. But I couldnt handle that

          – hakan
          Mar 8 at 12:35



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063052%2fwhy-navigator-geolocation-watchposition-not-work-in-setinterval%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко