javascript - 为什么不触发回调函数?
问题描述
我有这个功能,指示是否在浏览器上启用了地理定位:
function geolocationInfo() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
}
else {
return "Geolocation not works in this browser";
}
}
function success(position) {
var crd = position.coords;
console.log('Ваше текущее метоположение:');
console.log(`Широта: ${crd.latitude}`);
console.log(`Долгота: ${crd.longitude}`);
console.log(`Плюс-минус ${crd.accuracy} метров.`);
}
function error(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
return "Geolocation disabled";
case error.POSITION_UNAVAILABLE:
return "GeoLocation is not available";
case error.TIMEOUT:
return "Time is ends";
case error.UNKNOWN_ERROR:
return "error.";
}
}
问题是没有触发回调函数。
知道为什么不触发回调(成功和错误)吗?
解决方案
推荐阅读
- javascript - 如何在不修改函数的情况下处理 JavaScript 中的函数调用
- haskell - MonadTransControl 是否支持 STM?
- regex - 正则表达式检查右括号
- angular - 主题的可选参数
- python - Using Pandas Dataframe to perform comparison
- c# - VS2019 - 为对象、集合和数组初始化器插入新行不起作用
- python - 在python的单个元素列表中检查字符串是否存在的有效方法是什么
- javascript - 使用 javascript 中的 2 个按钮添加和删除文本(条件:使用 div id 'divResult' ,控制台日志。)
- r - 为什么我在使用管道和基本功能时大多会收到“'...' is not empty”错误?
- shopify - 如何从产品页面将第二个产品添加到 Shopify 中的购物车