admin管理员组文章数量:1403371
My current site is fully depends on the current location. Right now i am using geolocation for getting current location. But in current situation user is confused about the share location. So i want to created one custom pop-up (bootstrap) for get current location of the clients PC.
My current code is as below:
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, error, {enableHighAccuracy:true,timeout:60000,maximumAge:0});
}
else {
console.log("Geolocation is not supported by this browser.");
}
}
function error(error) {
console.log(error);
}
function showPosition(position) {
var latitude = position.coords.latitude,
longitude = position.coords.longitude;
console.log(latitude);
console.log(longitude);
}
Please help me on this concern.
My current site is fully depends on the current location. Right now i am using geolocation for getting current location. But in current situation user is confused about the share location. So i want to created one custom pop-up (bootstrap) for get current location of the clients PC.
My current code is as below:
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, error, {enableHighAccuracy:true,timeout:60000,maximumAge:0});
}
else {
console.log("Geolocation is not supported by this browser.");
}
}
function error(error) {
console.log(error);
}
function showPosition(position) {
var latitude = position.coords.latitude,
longitude = position.coords.longitude;
console.log(latitude);
console.log(longitude);
}
Please help me on this concern.
Share Improve this question asked Jan 12, 2017 at 11:52 Ravi PatelRavi Patel 7631 gold badge7 silver badges22 bronze badges 4- 1 What is the problem with the code? – Teemu Commented Jan 12, 2017 at 11:54
- if you're want to use bootstrap, read about their modals, it's pretty easy to create – Roljhon Commented Jan 12, 2017 at 11:56
- @Teemu The code is working fine but i want to create custom popup for get geolocation permission rather than custom location popup from the user. – Ravi Patel Commented Jan 12, 2017 at 12:01
- @Roljhon Yes i have idea about the bootstrap model. But to create custom pop-up for get permission for the clients PC permission. I have search a lot for the same but i am not able to fine any way to do it. – Ravi Patel Commented Jan 12, 2017 at 12:04
1 Answer
Reset to default 4There is now way to go around the browser's geolocation permission popup. On Chrome, it looks like this:
The user will need to click Allow before you can read their location (this is a security feature). However, if you absolutely need it, you could detect if the permission has been denied and explain to the user how to grant permission and why it's important.
See this answer to a similar question and this example to detect "permission denied" errors:
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, positionError);
} else {
console.log("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
// Success, can use position.
console.log("Your position is: " + position);
}
function positionError(error) {
if (error.PERMISSION_DENIED) {
console.log("Error: permission denied");
// Your custom modal here.
showError('Geolocation is not enabled. Please enable to use this feature.');
} else {
// Handle other kinds of errors.
console.log("Other kind of error: " + error);
}
}
function showError(message) {
// TODO
}
getLocation();
本文标签: javascriptCustom Popup for get my current locationStack Overflow
版权声明:本文标题:javascript - Custom Popup for get my current location - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744385191a2603704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论