ionic-framework - Ionic2 和 3 地理位置错误 : Only secure origins are allowed, 获取位置时出错并且无法在设备上工作

标签 ionic-framework ionic2

好吧,这就是发生的事情,我已经尝试了很多次让地理定位在 Android 设备上工作,但没有任何反应,而是显示白屏。我决定通过运行 ionic cordova run android -l -c 来使用模拟器进行测试,然后我发现它抛出异常仅允许安全来源。然后我尝试使用我从某人那里得到的解决方案 (platform.ready().then(() => { ) 在调用 geolocation getcurrentPosition 之前,我为 android 构建了应用程序并进行了测试,它仍然显示白屏。我使用模拟器运行,异常更改为控制台日志:获取位置时出错,我真的需要帮助,任何人。

我在 Node.js 7.8.0 上运行 ionic 3.4.0 和 npm 5.0.3

Home.ts

getMapLocation() {

   var options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumAge: 5000
    };


    /* Ensure the platform is ready */
   this.platform.ready().then(() => {
     console.log("platfrom is ready");

    /* Perform initial geolocation */
    this.geolocation.getCurrentPosition(options).then((position) => {
        console.log(position.coords.latitude)
        this.Latitude = position.coords.latitude;
        this.Longitude = position.coords.longitude;

     var pos = {
              lat: this.Latitude,
              lng: this.Longitude
            };

    this.location = pos;

     this.getMap(this.Latitude, this.Longitude);

    }).catch((err) => {
        console.log('Error getting location', err);
    });
})


}

Config.Xml

<universal-links>
        <host name="tgp38.app.goo.gl" scheme="https" />
        <host name="taxi-59a68.firebaseapp.com" scheme="https">
            <path url="/__/auth/callback" />
        </host>
    </universal-links>
    <feature name="StatusBar">
        <param name="ios-package" onload="true" value="CDVStatusBar" />
    </feature>
    <allow-navigation href="http://192.168.8.101:8100" />
    <allow-navigation href="http://192.168.8.103:8100" />
    <allow-navigation href="http://192.168.8.102:8100" />
    <engine name="android" spec="^6.2.3" />
    <plugin name="cordova-plugin-browsertab" spec="^0.2.0" />
    <plugin name="cordova-plugin-buildinfo" spec="^1.1.0" />
    <plugin name="cordova-plugin-compat" spec="^1.0.0" />
    <plugin name="cordova-plugin-device" spec="^1.1.6" />
    <plugin name="cordova-plugin-geolocation" spec="^2.4.3" />
    <plugin name="cordova-plugin-inappbrowser" spec="^1.7.1" />
    <plugin name="cordova-plugin-network-information" spec="^1.3.3" />
    <plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
    <plugin name="cordova-plugin-statusbar" spec="^2.2.3" />
    <plugin name="cordova-plugin-stripe" spec="^1.4.1" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
    <plugin name="cordova-universal-links-plugin" spec="^1.2.1" />
    <plugin name="cordova.plugins.diagnostic" spec="^3.6.5" />
    <plugin name="ionic-plugin-keyboard" spec="^2.2.1" />

AndroidManifest.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.playheavens.taxihub" xmlns:android="http://schemas.android.com/apk/res/android">
  <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true"/>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
      <intent-filter android:label="@string/launcher_name">
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:host="tgp38.app.goo.gl" android:scheme="https"/>
      </intent-filter>
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:host="taxi-59a68.firebaseapp.com" android:scheme="https" android:path="/__/auth/callback"/>
      </intent-filter>
    </activity>
    <receiver android:name="cordova.plugins.Diagnostic$LocationProviderChangedReceiver">
      <intent-filter>
        <action android:name="android.location.PROVIDERS_CHANGED"/>
      </intent-filter>
    </receiver>
    <receiver android:name="cordova.plugins.Diagnostic$NFCStateChangedReceiver">
      <intent-filter>
        <action android:name="android.nfc.action.ADAPTER_STATE_CHANGED"/>
      </intent-filter>
    </receiver>
  </application>
  <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25"/>
  <uses-feature android:name="android.hardware.location.gps"/>
</manifest>

最佳答案

“livereload”有问题。 Google 的新安全规则现在仅允许 https 端口。

因此,如果您在浏览器中运行,请尝试使用 https://localhost:8100 。如果您在设备中运行,请在没有 livereload 选项的情况下运行它。

关于ionic-framework - Ionic2 和 3 地理位置错误 : Only secure origins are allowed, 获取位置时出错并且无法在设备上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44617558/

相关文章:

angular - Ionic应用程序中的超时错误处理-Ionic

javascript - 在 ion-slide 中设置不同的 html 文件

javascript - Ionic fab 按钮在 App 中显示不正确

javascript - 使用 css 渐变和 javascript 创建动画

angular - Ionic2:如何使用 NavOptions 更改 Navigation Controller 的默认推送动画?

dependency-injection - 如何创建依赖于 ionic 2/angular 2 并使用依赖注入(inject)的库

android - 接收 Cordova/Ionic 格式的 URL

ios - ionic2 - 在 iOS v10 中嵌入没有声音的 youtube 视频播放

css - 如何防止 ionic 卡中的自动调整图像大小

angular - 文件输入不适用于 Vanilla 小米红米系列