Skip to content Skip to sidebar Skip to footer

How To Detect Negative User Response For Geolocation

When using geolocation API's navigator.geolocation.getCurrentPosition() how to deal with a negative response? It says that the second callback function is called when there is an e

Solution 1:

See edit below You are correct, the error handler should fire when a user denies the location request. The error object passed into the error handler should contain an error code and message letting you know the user denied the request. However, I'm not seeing this in FF4 when selecting the option Not Now from the location request dialogue.

In Chrome, the API/callbacks work exactly as expected, but in Chrome there is no 3rd option.

EDIT Ahhh okay I found a little quirk in the behavior of this in FF4. In normal mode (not private browsing), the user will be presented 3 options:

  • Always share
  • Never share
  • Not Now

Never share triggers the error handler correctly, but Not Now does not. What does this mean and how to handle it?

Well, it looks like if the user hits Not Now, you aren't going to get a response. Therefore, I would set a timeout which checks a flag that would be set by one of the handlers. If this flag is not set (meaning the handlers didn't fire in the allotted time), you can do one of two things:

  1. Assume that the user denied the request (even though the denial was temporary)
  2. You can ask the user for permission again (via the same call) and the user will be presented with the dialog again.

Option 2 is probably bad usability (and annoying), so it is probably best to assume they denied temporarily and ask them again (politely!) the next time they visit the site.


I created a JsFiddle to play around with this API:

http://jsfiddle.net/7yYpn/11/

Solution 2:

I don't think it's a bug, but an intentional choice when it comes to making it difficult to make websites that provides undesirable functionalities.. (as the top answer implied; IF you request again- when someone already said no- is rather annoying...)...

The difference between "not now".. and "never".. is that the programmer of the website KNOWS.. that if "not now" was triggered.. there would be an actual prompt to the user IF he sent the request again.. hence he would be able to "force" the user's hand to EITHER accept it.. or simply block data until the user agrees..

Decent and respectful programmers want to use such information to better provide a service (and to not wait for things that won't happen).. but truth is that there are enough spammers out there to overwhelm the end user..

(and there is no need to even TRY to send the request again, if it has been answered with "never".. because.. the user will not be terrorized in the same manner.. and if the site becomes sluggish and unresponsive, the user will just close it)

Ps. OH, and SERIOUS programmers might actually take a rejection as an actual.. rejection.. and store this choice somewhere.. despite the fact that "not now" is actually not intended as an ABSOLUTE rejection, but rather a "I have decided to not take any definite stand as of yet".. so.. someone who say "not now".. if the server knows of this choice and takes it as a "no".. then there might NEVER be another request sent.. despite the person WANTING to be able to reconsider at a later date)

Post a Comment for "How To Detect Negative User Response For Geolocation"