简体   繁体   English

在离子应用程序中获取地理位置时出错

[英]Error in getting geolocation in ionic application

I am building an ionic application in which i need geolocation of the device. 我正在构建一个离子应用程序,我需要设备的地理定位。 For that i am using cordova-plugin-geolocation and my code is this : 为此,我使用cordova-plugin-geolocation ,我的代码是这样的:

在此输入图像描述

But i am getting this error again and again. 但我一次又一次地得到这个错误。

在此输入图像描述

I searched a lot of stuff on internet but do not found anything useful. 我在互联网上搜索了很多东西,但没有找到任何有用的东西。 Do anybody has any idea or suggestion in order to solve this problem ? 为了解决这个问题,有人有任何想法或建议吗?

It seems like google no more support HTTP but is it even possible to make my ionic application HTTPS ? 似乎谷歌不再支持HTTP,但它甚至可以使我的离子应用程序HTTPS?

Cordova plugins don't work on browser. Cordova插件不适用于浏览器。

If you want to test it on browser you have to add 如果您想在浏览器上测试它,您必须添加

cordova plugin add browser

And then to run your ionic app use 然后运行您的离子应用程序使用

cordova run browser

not every plugin will work on cordova browser. 并非每个插件都可以在cordova浏览器上运行。 Further you might have to emulate or build the app and test it out. 此外,您可能必须模拟或构建应用程序并进行测试。

Update : You need to call all functions one the device is ready. 更新 :您需要在设备就绪之前调用所有功能。

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    //All your code here.
}

Before your device is ready you won't fetch any value of your location. 在您的设备准备好之前,您将无法获取您所在位置的任何值。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM