Closed Bug 1057242 Opened 11 years ago Closed 11 years ago

Use setInterval function with GeoLocation API to set manual timeout for user choice

Categories

(Core :: General, defect)

31 Branch
x86_64
Windows 8.1
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: pradosh.manerkar, Unassigned)

References

()

Details

User Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0 (Beta/Release) Build ID: 20140716183446 Steps to reproduce: I use geolocation API on a website. I have written a code whereby I set a timeout (using a setInterval function) after I call the getcurrentposition method. My objective is to show him an alert (which tells him that we are detecting his location) and detect the location by ID address if the user does not select any option. I maintain a flag which is set in the success, fail and error callback of the getCurrentPosition function. I check for the flag in the callback of the setInterval function and alert the user only if the flag is false ie. he has not taken any action. Actual results: The code is working perfectly in all browsers except Mozilla. In Mozilla, even after the user clicks on "Share Location" (or any other option) the flag is still false when the setInterval callback is executed. In my opinion, the callbacks for the getCurrentPosition are fired later than the setInterval callback. However, I cannot think of any reason for that.
Summary: Set Manual timeout → Use setInterval function with GeoLocation API to set manual timeout for user choice
(In reply to pradosh.manerkar from comment #0) > The code is working perfectly in all browsers except Mozilla. In Mozilla, > even after the user clicks on "Share Location" (or any other option) the > flag is still false when the setInterval callback is executed. In my > opinion, the callbacks for the getCurrentPosition are fired later than the > setInterval callback. However, I cannot think of any reason for that. Err, it takes longer to get the location, for whatever reason? Do you cancel the setInterval, or does it run again? Why don't you just update the alert when the permission callbacks for the location fire? Can you provide a more minimal testcase? The page at http://www.traffline.com/ works for me in Firefox 32 (detects my location correctly, at least, and I never see an alert that I can tell).
Flags: needinfo?(pradosh.manerkar)
Product: Firefox → Core
Hi Gijs, MY requirement is as follows :- I want the browser to ask the user to share his location. If he does not take a decision, for whatever reason, I want show him an alert saying "Sorry, we still haven't received an update on your location sharing preference yet. Worry not, we will go ahead and select a city for you.". How you can test this: Reload the page and DO NOT CLICK any preference. You will see the alert I am talking about. It seems the first time around you clicked on the "Share Location" button too soon. Wait for 4-5 secs and see. The problem here is even if I click on "Share Location" I still end up seeing the alert which should not be the case logically. I did consider prolonging the interval but I wanted to check if there is some other problem first. Hope I have clarified your doubt.
Flags: needinfo?(pradosh.manerkar)
(In reply to pradosh.manerkar from comment #2) > How you can test this: > Reload the page and DO NOT CLICK any preference. You will see the alert I am > talking about. It seems the first time around you clicked on the "Share > Location" button too soon. Wait for 4-5 secs and see. > > The problem here is even if I click on "Share Location" I still end up > seeing the alert which should not be the case logically. > I did consider > prolonging the interval but I wanted to check if there is some other problem > first. > > Hope I have clarified your doubt. I'm afraid not. The first paragraph I quote above, you seem to be saying "don't click 'share location' in the doorhanger, wait for the alert". In the second, you seem to be saying "if I do click it, I still get an alert". But as I said in comment #1, if I do click it, I don't get an alert. I also pointed out that it's totally possible for there to be a race condition - if you click the "Share Location" button about 6 seconds after the notification appears (seeing as the alert timeout is for 7 seconds), I can reproduce the alert showing despite my having clicked "Share Location". However, I can reproduce the same issue on Chrome. The browser doesn't and can't give you a guarantee that the success callback for getCurrentPosition is called synchronously as soon as "Share Location" is called, because the data is not synchronously available (in most cases, we'll need to send a list of wifi access points to google's location service - it is likely chrome does the same under the hood). In other words, the guarantee you're looking for (that your success callback is called synchronously with a position as soon as the user clicks "Share Location") isn't there in the API, the spec, or in other browsers. I'm going to mark this invalid because I don't think this is a bug (as we do the same as other browsers and comply with the spec).
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
Moving from Core::Untriaged to Core::General https://bugzilla.mozilla.org/show_bug.cgi?id=1407598
Component: Untriaged → General
You need to log in before you can comment on or make changes to this bug.