In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to deal with shared location data in JavaScript". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to deal with shared location data in JavaScript" can help you solve your doubts.
There may be situations where users do not want to share their location data with you. To handle this situation, you can provide two getCurrentLocation () functions when the function is called.
If your geolocation attempt is successful, the first function is called, and if your geolocation attempt fails, the second function is called. Let's look at an example:
Try this code for example »
Handling Geolocation Errors
/ / Set up global variable
Var result
Function showPosition () {
/ / Store the element where the page displays the result
Result = document.getElementById ("result")
/ / If geolocation is available, try to get the visitor's position
If (navigator.geolocation) {
Navigator.geolocation.getCurrentPosition (successCallback, errorCallback)
Result [XSS _ clean] = "Getting the position information..."
} else {
Alert ("Sorry, your browser does not support HTML5 geolocation.")
}
}
/ / Define callback function for successful attempt
Function successCallback (position) {
Result [XSS _ clean] = "Your current position is (" + "Latitude:" + position.coords.latitude + "," + "Longitude:" + position.coords.longitude + ")"
}
/ / Define callback function for failed attempt
Function errorCallback (error) {
If (error.code = = 1) {
Result [XSS _ clean] = "You've decided not to share your position, but it's OK. We won't ask you again."
} else if (error.code = = 2) {
Result [XSS _ clean] = "The network is down or the positioning service can't be reached."
} else if (error.code = = 3) {
Result [XSS _ clean] = "The attempt timed out before it could get the location data."
} else {
Result [XSS _ clean] = "Geolocation failed due to unknown error."
}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.