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

  • Home
  • SEARCH
  • 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 8331417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:24:44+00:00 2026-06-09T02:24:44+00:00

My Problem: It takes two page loads from my mobile browser (testing with iphone)

  • 0

My Problem:
It takes two page loads from my mobile browser (testing with iphone) to get an accurate result. The first load will be half a mile or more off, and then the second load will be very close.

My question:
What needs to be done to get the accurate location on the first load?

Extra Info:

I’ve read through http://www.w3.org/TR/geolocation-API/ and am taking advantage of watchPosition with the enableHighAccuracy. Also I am using maximumAge:0 and timeout not set.

From http://www.w3.org/TR/geolocation-API/

If maximumAge is set to 0, the implementation must immediately attempt to acquire a new position object

the default value used for the timeout attribute is Infinity

My code is listed below

// Try HTML5 geolocation
    if(navigator.geolocation) {

    // updated this with watchPosition rather than getCurrentPosition
      navigator.geolocation.getCurrentPosition(function(position) {
        var pos = new google.maps.LatLng(position.coords.latitude,
                                         position.coords.longitude);

        var infowindow = new google.maps.InfoWindow({
          map: map,
          position: pos,
          content: 'Location found using HTML5.'
        });

        map.setCenter(pos);
      }, function() {
        handleNoGeolocation(true);
      },
    // enable high accuracy
    //  {maximumAge:100, timeout:5000, enableHighAccuracy: true}
            // 
                {maximumAge:0, enableHighAccuracy: true}
      );
    } else {
      // Browser doesn't support Geolocation
      handleNoGeolocation(false);
    }
  }

  function handleNoGeolocation(errorFlag) {
    if (errorFlag) {
      var content = 'Error: The Geolocation service failed.';
    } else {
      var content = 'Error: Your browser doesn\'t support geolocation.';
    }
  • 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-09T02:24:46+00:00Added an answer on June 9, 2026 at 2:24 am

    I have the solution to getting the most accurate geolocation possible. You need to call clearWatch() after a given timeout. The timeout maybe time and or an event such as form click.

    In my application I use a 5 second timeout and a click of a form element.

    Here’s all the useful code snippets.

    Set the onclick

    <select onclick="aFormClick()" id="location"
    

    Set the timeout in the function that is the parent of the watchPosition function

    setTimeout("stopWatchPosition()",5000);
    

    Create a function to listen for the form click

    function aFormClick(){
    stopWatchPosition();
    }
    

    Create the function for calling clearnWatch()

    function stopWatchPosition(){
    if (clearWatchCalled == 0){
        navigator.geolocation.clearWatch(watchID);
        clearWatchCalled++;
    }
    }
    

    Make sure your watchPosition can be referenced by the ID

    watchID = navigator.geolocation.watchPosition(function(position) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Everything works fine, the only problem is that it loads very slow. It takes
I am running into this problem where my page loads and then after a
I have a small problem that takes me for a day and until now
The problem is that it takes way to long in SQL and there must
Problem Hello all! I have this code which takes my jpg image loops through
So here's my problem: I've created a custom AVCaptureSession that takes pictures. I'm not
I'm having a problem with a cocoa application that takes the value of a
I'm having a problem with this query that takes several seconds to complete. I
I have a problem here that requires to design a data structure that takes
I have got a problem with calling a global function, which takes a pointer

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.