Javascript 应用程序没有';我没抓住这个位置
我正在使用PhoneGap为一个大学项目构建应用程序,我需要抓住我的位置,但getCurrentPosition没有运行。 我也尝试过,但没有任何改变(还有关于安全上下文的警告,我找不到解决方案) 这是代码:Javascript 应用程序没有';我没抓住这个位置,javascript,jquery,html,position,phonegap,Javascript,Jquery,Html,Position,Phonegap,我正在使用PhoneGap为一个大学项目构建应用程序,我需要抓住我的位置,但getCurrentPosition没有运行。 我也尝试过,但没有任何改变(还有关于安全上下文的警告,我找不到解决方案) 这是代码: $(document).ready(function() { var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; fun
$(document).ready(function() {
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
console.log(`More or less ${crd.accuracy} meters.`);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
}
$("#update").click(function() {
navigator.geolocation.getCurrentPosition(success, error, options);
});
}
我做错了什么?可能是我必须在我点击的文件中声明的东西
已解决
问题出在浏览器上。我手动解决了它,接受了位置权限,然后它也在Android Studio emulator中工作。“关于安全上下文的警告”告诉您,页面需要使用HTTPS才能使用地理位置API。@Turnip“需要使用HTTPS”是什么意思?我正在使用
phonegap-service
(我也需要在Android Studio emulator中运行它),我无法更改上下文…如果您正在使用phonegap,那么您需要在问题中提到这一点并添加相应的标记。我没想到这会是phonegap问题。。。