简体   繁体   English

Cordova的地理位置插件如何工作?

[英]How does Cordova's Geolocation Plugin work?

I am building an app (on android and iOS) that wants the device's current location using the ionic framework (cordova, ionic, angular). 我正在构建一个应用程序(在android和iOS上),该应用程序使用ionic框架 (cordova,ionic或angular)来希望设备的当前位置。 For that I have been trying to use Cordova's Geolocation Plugin . 为此,我一直在尝试使用Cordova的Geolocation插件 During my research, I found out that the cordova guys have deprecated the native geolocation implementation because the browser's geolocation was much more efficient HERE . 在研究过程中,我发现Cordova家伙已经弃用了本机地理位置实现,因为浏览器的地理位置在这里效率更高。 I hoped this was the reason why when I build my app the config.xml file did not contain 我希望这就是为什么在我构建应用程序时config.xml文件不包含的原因

<feature name="Geolocation">
    <param name="android-package" value="org.apache.cordova.geolocation.GeoBroker" />
  </feature>

But on implementing the plugin on my app, the plugin seemed to get the location just fine when my GPS was on but it could not get the location it my GPS was off. 但是在我的应用程序上实现该插件时,当我的GPS开启时,该插件似乎可以很好地定位,但是无法获取我的GPS处于关闭状态的位置。 Which is completely counter-intuitive to me. 这完全违反我的直觉。 What am I missing here? 我在这里想念什么? Did I understand wrong when they said they deprecated the android geoloction plugin? 当他们说他们弃用了android geoloction插件时,我理解错了吗? I want to know what exactly happens when the geolocation plugin requests for the device's location. 我想知道当地理位置插件请求设备位置时到底发生了什么。

Thanks in advance. 提前致谢。

It sounds like the Geolocation is only happening with the GPS and not with WiFi or cellular triangulation. 听起来地理定位发生在GPS上,而不发生在WiFi或蜂窝三角测量上。

The Docs 文件

The plugin has an option for enableHighAccuracy . 该插件具有enableHighAccuracy 选项 期权文件

There is an Android bug: 有一个Android错误: Android错误

Compare the 3 Location Methods 比较3种定位方法

A GPS chip connects directly to satellites. GPS芯片直接连接到卫星。 Cellular triangulation makes use of your phone's signal. 蜂窝三角测量可利用手机的信号。 It is used, for example, in some emergency services to locate you by triangulating how far your phone is from the towers. 例如,它在某些紧急服务中用于通过三角测量手机与塔楼的距离来找到您的位置。 Here's an interesting Reddit article on a comparison between GPS and cell triangulation. 这是一篇有关GPS与单元三角测量之间比较的有趣Reddit文章。 Wifi can also improve location accuracy: see two discussions regarding how Google does this. Wifi还可以提高位置准确性:有关Google如何做到这一点的两个 讨论

In Short 简而言之

There are two damned if you do, damned if you don't issues: 如果您这样做,该死的有两个, 如果您不发行,则该死的有两个:

  1. The bug: if enableHighAccuracy isn't set to true, the emulator won't return anything; 错误:如果enableHighAccuracy未设置为true,则模拟器不会返回任何内容; it doesn't matter if you have your GPS on or not. 是否开启GPS都没关系。
  2. High accuracy: because you want the emulator to work, you set enableHighAccuracy to true, but this will mean that you must keep the GPS turned on. 高精度:因为您希望仿真器能够工作,所以将enableHighAccuracy设置为true,但这意味着您必须保持GPS处于打开状态。

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

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