简体   繁体   English

Ionic with Android Emulator:自动发送位置?

[英]Ionic with Android Emulator: Automatically send location?

I'm having an issue with my android emulator. 我的android模拟器有问题。 When I close and re-open my app, the location is not sent automatically. 当我关闭并重新打开我的应用时,该位置不会自动发送。 I have to go into Extended Controls -> Location and click the 'Send' button for the Ionic Geolocation getCurrentPosition function to receive it. 我必须进入扩展控件 - >位置,然后单击Ionic Geolocation getCurrentPosition函数的“发送”按钮来接收它。

When I boot up the android emulator and the app opens for the first time, this is not necessary. 当我启动Android模拟器并且第一次打开应用程序时,这不是必需的。 Any idea how to send the location automatically no matter what? 知道如何自动发送位置无论如何?

Generally for the Testing of Plugins we need to verify in the real device, but as your original question about using it in Emulators, for this to work out , 一般来说,对于插件的测试,我们需要在真实设备中进行验证,但作为您在仿真器中使用它的原始问题,为了解决这个问题,

  1. Try to clear the cordova Cache ( if you are using Visual Studio , you can do it like Tools->Options ) 尝试清除cordova Cache(如果您使用的是Visual Studio,则可以像工具 - >选项一样

  2. Try to add watchPosition function with enableHighAccuracy : true 尝试使用enableHighAccuracy : true添加watchPosition函数enableHighAccuracy : true

 navigator.geolocation.watchPosition(onSuccess, onError, { timeout:40000, enableHighAccuracy: true }); 

Update : 更新:

After a quick googling , found this link , It states that : 经过快速谷歌搜索,发现链接,它声明:

Starting with Chrome 50, Chrome no longer supports obtaining the user's location using the HTML5 Geolocation API from pages delivered by non-secure connections. 从Chrome 50开始,Chrome不再支持使用来自非安全连接提供的网页的HTML5 Geolocation API来获取用户的位置。 This means that the page that's making the Geolocation API call must be served from a secure context such as HTTPS. 这意味着必须从安全上下文(如HTTPS)提供进行Geolocation API调用的页面。

A possible solution can be like : 可能的解决方案可能是:

By adding appropriate permissions on Android platform, open your project, search for AndroidManifest.xml and add these lines: 通过在Android平台上添加适当的权限,打开您的项目,搜索AndroidManifest.xml并添加以下行:

<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_LOCATION_EXTRA_COMMANDS" />

For more Info Read this article and this thread 欲了解更多信息阅读文章, 这个线程

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

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