javascript - navigator.geolocation.getCurrentPosition sometimes works sometimes doesn't -
Then I have a very easy JS using Navigator.Golicy .getCurrentPosition jammy.
$ (document) .ready (function () {$ ("# business-locate, # people-locate"). Click (function () {navigator.geolocation.getCurrentPosition (foundLocation, NoLocation;;); Navigator Geolocation.getCurrentPosition (foundLocation, noLocation); Function FoundOption (position) {var lat = position.coords.latitude; var lon = position.coords.longitude; var User Location = Latitude "," + + After that ("& lt; input type = 'hidden' name = 'business, current location, # people-current-location"), remove () "$" ("# business-watermark" ("current location"). ; $ ("# Near-me" $ ("# people-min-me") Watermark ("current location"). Lt; input type = 'hidden' name = 'people-current-location' id = 'people-current-location' value = '"+ use RLocation +"' />;);} function nullation () {$ ("# Near-me") Watermark ("Could not find location"); $ ("# people-mean-me") Watermark ("Could not find location"); what is actually happening here We get the current position, if it is obtained, two "watermarks" are placed in two areas called "current status" and two. Hidden areas are made with data in their form of latitude (they are initially deleted, so they are not repeated every time). There are also two buttons which have a click function that do the same thing. Unfortunately, every third or so, it works. What is the problem here ???
I'm absolutely the problem, and almost no notice about it Nothing to Search Online In the Book Finally, I found this cool query at StackHowforFlow and (Ha!) This was the last motivation that I needed to open an account. And I have a partial answer, but regret is not a complete one.
First of all, know that getCurrentPosition is Default Timeout for Infinity (!). This means that your error handler will never be called if you should get it, you can find it on the back end. To ensure that you get timeout, add the optional column to your call GetCurrentPosition, for example, if you do not want users to wait for more than 10 seconds, Use this before giving clues:
Navigator. Global Cache. Get gatecountry (success callback, error callback, {timeout: 10000});
Second, I have experienced quite a different reliability in different contexts. At home here, I get a callback within one or two, though the accuracy is bad.
However, I have a lot of bizarre diversities in practice: Geolocation works on some computers at all times (except IE, of course), others work in chrome and safari, but firefox (gun issue? ) Other people do not work once, they fail later - and patterns change every day from time to time Sometimes you have a 'lucky' computer, sometimes it does not. Probably will help kill goats in full moon?
I am not able to understand this, but I suspect that the infrastructure behind is more unequal than advertising
books and websites that are pushing this facility forward. I would really like to be a little more straightforward about this feature, and how important that timeout setting is, if you want your error handler to work properly .
Today, I am trying to teach these things to the students and in a shameful situation where my own computer (projector and many large screens) was failing silently, while about 80% Immediately being the exact same wireless network) When my students are also making typo and other graphs, then these issues are difficult to solve, and even when my own PC is also unsuccessful.
Still, I hope this will help some of you. Thanks for the discretion investigation!
Comments
Post a Comment