Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 地理定位在爱奥尼亚4安卓系统中不起作用_Ionic Framework_Geolocation_Android Emulator_Ionic Native_Ionic4 - Fatal编程技术网

Ionic framework 地理定位在爱奥尼亚4安卓系统中不起作用

Ionic framework 地理定位在爱奥尼亚4安卓系统中不起作用,ionic-framework,geolocation,android-emulator,ionic-native,ionic4,Ionic Framework,Geolocation,Android Emulator,Ionic Native,Ionic4,为了获取Android设备中的当前位置,我使用了Ionic 4插件,并按照文档中给出的步骤进行操作。在运行Ionic CLI命令Ionic cordova run android--l--c时,它会启动应用程序并提示“位置权限”对话框。但它会抛出一个错误,如getCurrentPosition()和watchPosition()在不安全的源代码上不受欢迎。要使用这个特性,您应该考虑将应用程序切换到安全的原点。< /代码> { PositionErrorcode: 1message: "O

为了获取Android设备中的当前位置,我使用了Ionic 4插件,并按照文档中给出的步骤进行操作。在运行Ionic CLI命令Ionic cordova run android--l--c时,它会启动应用程序并提示“位置权限”对话框。但它会抛出一个错误,如
getCurrentPosition()和watchPosition()在不安全的源代码上不受欢迎。要使用这个特性,您应该考虑将应用程序切换到安全的原点。< /代码> 

{
   PositionErrorcode: 1message: "Only secure origins are allowed ."__proto__: PositionError
   home.page.ts:37Error getting location PositionError
}
同样在阅读了论坛中的博客和帖子之后,我只使用了cli命令
ionic cordova run android
(无需重新加载)。在这种情况下,应用程序没有加载,因为源没有正确加载

Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///polyfills.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///styles.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///cordova.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///vendor.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///main.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///assets/icon/favicon.png Failed to load resource: net::ERR_FILE_NOT_FOUND

我还尝试使用emulator扩展控件在emulator中设置gps位置。在真实设备中尝试过,它也有这样的问题。

不推荐使用不安全(HTTP)上下文访问用户位置。 看

这只是使用实时重新加载时的一个问题


这将起作用,ionic cordova build android

访问用户位置不推荐使用不安全(HTTP)上下文。 看

这只是使用实时重新加载时的一个问题


这将在两个部分中起作用,我将尽力提供帮助,我遇到了同样的两个问题,我将解释我是如何“修复”它们的,也许它也适用于您

(1) 关于这一错误:

Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///polyfills.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///styles.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///cordova.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///vendor.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///main.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///assets/icon/favicon.png Failed to load resource: net::ERR_FILE_NOT_FOUND
老实说,我不确定到底是什么原因导致了这一点,我仍在调查根本原因,因为我有这个问题,以防它回来。奇怪的是,我在Android上遇到了这个问题,但在iOS平台上却没有。我所做的是清除所有插件并重新安装:

// Inside your app's folder
$ rm -rf plugins 
// Just in case (I didn't do it, but who knows!) remove and add the platform again
$ ionic cordova platform remove android
$ ionic cordova platform add android
之后,这些错误就消失了

(2) 关于地理位置

是的,这是真的,我阅读了有关HTTP/HTTPs的文档,并且在通过浏览器使用时也有警告。 我没有让地理定位在设备(iOS和Android)上工作,只是在编写了爱奥尼亚的文档所说的代码之后,它没有得到任何生命的信号。我认为这是因为地理定位(HTTP/HTTPs)的问题

因此,我发现在设备(Android和iOS)上,地理定位工作正常,如果在平台准备就绪后启动它们(或者使用Timeout参数,作为替代)。 使设备获取用户位置的代码如下:

   this.platform.ready().then(() => {
        this.geolocation.getCurrentPosition().then((loc) => {
              userLatitude  = loc.coords.latitude;
              userLongitude = loc.coords.longitude;
              map.flyTo({userLatitude:userLongitude}, MAX_ZOOM - 2, ZOOM_PAN_OPTIONS);
        }).catch((error) => {
            this.utils.error('Error getting location: ' + error.message);
        }); 
   };
我没有测试,但其他替代方法可能是在方法上使用
Timeout
参数:

this.geolocation.getCurrentPosition({ timeout: 30000 }).then((loc) => { ...

我认为有很多变量,考虑到所有的上下文,可以使这项工作或不工作。在我的例子中,它是这样发生的。

在两个部分中,我将尽力帮助,我遇到了同样的两个问题,我将解释我是如何“修复”它们的,也许它也适用于您

              this.geolocation.getCurrentPosition().then((resp) => {
                console.log(resp);
                // resp.coords.latitude
                // resp.coords.longitude
            }).catch((error) => {
                console.log('Error getting location', error);
            });
(1) 关于这一错误:

Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///polyfills.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///styles.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///cordova.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///vendor.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///main.js Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///assets/icon/favicon.png Failed to load resource: net::ERR_FILE_NOT_FOUND
老实说,我不确定到底是什么原因导致了这一点,我仍在调查根本原因,因为我有这个问题,以防它回来。奇怪的是,我在Android上遇到了这个问题,但在iOS平台上却没有。我所做的是清除所有插件并重新安装:

// Inside your app's folder
$ rm -rf plugins 
// Just in case (I didn't do it, but who knows!) remove and add the platform again
$ ionic cordova platform remove android
$ ionic cordova platform add android
之后,这些错误就消失了

(2) 关于地理位置

是的,这是真的,我阅读了有关HTTP/HTTPs的文档,并且在通过浏览器使用时也有警告。 我没有让地理定位在设备(iOS和Android)上工作,只是在编写了爱奥尼亚的文档所说的代码之后,它没有得到任何生命的信号。我认为这是因为地理定位(HTTP/HTTPs)的问题

因此,我发现在设备(Android和iOS)上,地理定位工作正常,如果在平台准备就绪后启动它们(或者使用Timeout参数,作为替代)。 使设备获取用户位置的代码如下:

   this.platform.ready().then(() => {
        this.geolocation.getCurrentPosition().then((loc) => {
              userLatitude  = loc.coords.latitude;
              userLongitude = loc.coords.longitude;
              map.flyTo({userLatitude:userLongitude}, MAX_ZOOM - 2, ZOOM_PAN_OPTIONS);
        }).catch((error) => {
            this.utils.error('Error getting location: ' + error.message);
        }); 
   };
我没有测试,但其他替代方法可能是在方法上使用
Timeout
参数:

this.geolocation.getCurrentPosition({ timeout: 30000 }).then((loc) => { ...
我认为有很多变量,考虑到所有的上下文,可以使这项工作或不工作。就我而言,事情就是这样发生的

              this.geolocation.getCurrentPosition().then((resp) => {
                console.log(resp);
                // resp.coords.latitude
                // resp.coords.longitude
            }).catch((error) => {
                console.log('Error getting location', error);
            });
我的问题打了两次电话

当您反复呼叫时,结果可能不会出现。 确保调用该函数一次。

我的问题打了两次电话

当您反复呼叫时,结果可能不会出现。
请确保调用该函数一次。

它不起作用。正如我在问题中提到的,如果我执行命令ionic cordova run android/ionic cordova build android,它会抛出错误,标题为加载资源失败:net::ERR_FILE_NOT_FOUND。这个特别的问题不仅仅针对这个项目。升级到爱奥尼亚4后,我在所有项目中都面临着这个问题。如果我添加“重新加载”选项,同样也可以。谢谢。试试这两个链接,可能会有帮助,但没有帮助。从index.html中删除会给我一个错误“error:No base href set.请为APP_base_href标记提供一个值或向文档添加一个base元素”。按照链接中的指示更改配置不会对结果造成任何更改。它不起作用。正如我在问题中提到的,如果我执行命令ionic cordova run android/ionic cordova build android,它会抛出错误,标题为加载资源失败:net::ERR_FILE_NOT_FOUND。这个特别的问题不仅仅针对这个项目。升级到爱奥尼亚4后,我在所有项目中都面临着这个问题。如果我添加“重新加载”选项,同样也可以。谢谢。试试这两个链接,可能会有帮助,但没有帮助。从index.html中删除会给我一个错误“error:No base href set.请为APP_base_href标记提供一个值或向文档添加一个base元素”。按照链接中的指示更改配置不会对结果造成任何更改。