Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9311997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:31:15+00:00 2026-06-19T01:31:15+00:00

I have a javascript script I’m developing for a phonegap app that gets device

  • 0

I have a javascript script I’m developing for a phonegap app that gets device location until a certain target accuracy is obtained. If the target isn’t met the script calls itself again into eternity. Usually it takes between 1-8 attempts depending on location and the last time used and then everything works fine. The problem I’m having is that some devices never reach that threshold (which is fine for the app), but ruins battery life because this script keeps running in the background. So how can I kill this script with a click event (the submit button)? I was thinking about setting a global var that hitting the submit button changes. Something like:

if (var != 'quit') {
    //function 
} else {
    ///nothing
}

function getlocation(position) {
    document.getElementById("lat").value = (position.coords.latitude);
    document.getElementById("long").value = (position.coords.longitude);
    document.getElementById("accu").value = (position.coords.accuracy);
    var accuracy = parseInt(position.coords.accuracy, 10);
    if (accuracy <= 50) {
        $('#scanner').removeClass('littlered').addClass('littlegreen');
    } else {
        setTimeout(navigator.geolocation.getCurrentPosition(getDroplocation, onError, {
            enableHighAccuracy: true
        }), 3000);
    }
}

This hasn’t been working though. I set the global var but nothing happens. Any better methods or ways of getting my aforementioned idea going? Am I on the right track?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T01:31:16+00:00Added an answer on June 19, 2026 at 1:31 am

    Use clearTimeout() method clears a timer set with the setTimeout() method.

    var to;
    
    function getlocation(position) {
        document.getElementById("lat").value = (position.coords.latitude);
        document.getElementById("long").value = (position.coords.longitude);
        document.getElementById("accu").value = (position.coords.accuracy);
        var accuracy = parseInt(position.coords.accuracy, 10);
        if (accuracy <= 50) {
            $('#scanner').removeClass('littlered').addClass('littlegreen');
        } else {
            to = setTimeout(navigator.geolocation.getCurrentPosition(getDroplocation, onError, {
                enableHighAccuracy: true
            }), 3000);
        }
    }
    
    //Add click event handler to a button to stop the looping
    var button = document.getElementById("testbtn");
    testbtn.onclick = function() {
        clearTimeout(to);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following JavaScript/jQuery script that gets an external html page using
I have Javascript as below: <script type="text/javascript" language="javascript"> function redirectToPrevious(abcURL) { window.location.replace(abcURL); } function
There are some pages have such javascript: <script language=javascript> if (top.location != location) top.location.href
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a javascript function that works as I would like : <script language=javascript
Given that I have a JavaScript section in my HTML page like : <script
I have a Javascript script that should work on weekends and at nights and
I have a pretty long javascript script. The problem is that in the middle
I have a function in my Javascript script that needs to talk with the
I have this javascript line <script type=text/javascript>document.write(top.location);</script> and this code <form action=rating.php method=post> <input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.