简体   繁体   English

GPS定位对于Android应用程序非常慢

[英]Geolocation with GPS very slow for an android app

I'm using intel xdk and cordova for an android app that uses geolocation this is the code that i use: 我正在为使用地理位置的android应用程序使用intel xdk和cordova,这是我使用的代码:

if(navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(geolocalizacion,error,{enableHighAccuracy:true, maximumAge:Infinity, timeout:100000});

  } else {   
    handleNoGeolocation(false);
  }

I don't want to use the 'google location service' because, if that option is disabled, some people can get lost trying to find it in settings, so i'm using enableHighAccuracy:true in order to use GPS. 我不想使用“ Google定位服务”,因为如果该选项被禁用,某些人可能会迷失在设置中查找它的位置,因此我使用enableHighAccuracy:true来使用GPS。

However with that it takes so much time, almost a minute to call the success function 'geolocalizacion' when the app is used indoors. 但是,在室内使用该应用程序需要花费大量时间,几乎要花一分钟时间才能调用成功功能“ geolocalizacion”。 I know that GPS is better in outdoors (in that case it takes 5 or 7 seconds) but i think 1 minute is too much for indoors. 我知道GPS在户外比较好(在这种情况下,需要5或7秒),但我认为1分钟对于室内来说实在太多了。

Am i doing something wrong? 难道我做错了什么?

Is there a way to make faster the geolocation with GPS? 有没有一种方法可以使GPS定位更快?

or a way to activate the 'google location service' without the user doing anything?. 还是无需用户执行任何操作即可激活“ Google定位服务”的方法?

The GPS signals transmitted by GPS satellites are very weak if you are not located outside. 如果您不在室外,则GPS卫星发送的GPS信号非常弱。 Even if you are outside, weather conditions, tall buildings and other large metal structures can hide or degrade the GPS signal. 即使您在外面,天气情况,高大的建筑物和其他大型金属结构也可能隐藏或削弱GPS信号。 In addition, the GPS receivers inside of your typical phone or tablet are very low grade receivers and antennas, they are not as capable as the more expensive dedicated GPS devices, due to compromises associated price and physical size. 此外,典型手机或平板电脑内部的GPS接收器是非常低级的接收器和天线,由于折衷了相关的价格和实际尺寸,它们不如更昂贵的专用GPS设备强大。

You should really take a two prong approach: get an initial reading using the "coarse" geo reading, with the geo cache enabled. 您实际上应该采取两种方法:使用“粗略”地理读数并启用地理缓存来获得初始读数。 The coarse reading will use the wifi, network, GPS and cached readings and return it's best estimate based on the parameters you specify, usually within a very reasonable time frame. 粗略的读数将使用wifi,网络,GPS和缓存的读数,并根据您指定的参数返回最佳估计值,通常是在非常合理的时间范围内。

Then, after you've established an approximate position (which can be very accurate, as @SeahawksRdaBest points out, if based on the current wifi), switch to the "fine" location setting to get an accurate position. 然后,在您确定了大概的位置(如果基于当前的wifi,它可能非常准确,如@SeahawksRdaBest指出),请切换到“精确”位置设置以获取准确的位置。 This part of your app can run in the background so it doesn't interrupt the responsiveness of your app, and can then update the position information in your app as more accurate position data becomes available. 应用程序的这一部分可以在后台运行,因此不会中断应用程序的响应速度,然后可以在应用程序中提供更准确的位置数据时更新位置信息。

One thing to keep in mind, many users have the GPS turned off because it severely degrades battery life. 要记住的一件事是,许多用户已关闭GPS,因为它会严重降低电池寿命。 If all your app needs is to "find a restaurant nearby" then the coarse location should be good enough, since you're probably more interested in placing the destination on the map. 如果您所有的应用程序需求都是“在附近找到餐厅”,那么粗略的位置应该足够好,因为您可能会对将目的地放置在地图上更加感兴趣。 This will be much more battery friendly, and is one of the reasons that the geo settings on the more recent Android devices have changed to make it harder for an app to enable GPS programmatically. 这将对电池更加友好,并且是最新的Android设备上的地理设置已更改,从而使应用程序难以以编程方式启用GPS的原因之一。

I see you've added the intel-xdk tag, so you might want to checkout this little geolocation test app that I've put together at https://github.com/xmnboy/hello-cordova . 我看到您已经添加了intel-xdk标签,因此您可能想要检出我在https://github.com/xmnboy/hello-cordova上放在一起的这个地理定位测试应用程序。 It needs a little work but should help you with some experimentation between coarse and fine settings. 它需要一些工作,但应该可以帮助您在粗略设置和精细设置之间进行一些试验。

I think you can diversify your app a little. 我认为您可以稍微扩展您的应用程序。

For example if you are indoors and have a WiFi connection why not use that to triangulate your position? 例如,如果您在室内并且有WiFi连接,为什么不使用它来三角定位您的位置? WiFi is highly accurate because theoretically it covers a small space so the phone would know exactly where it is and return a position quickly.(if done right in my experience usually <10 secs). WiFi高度准确,因为从理论上讲它覆盖的空间很小,因此手机可以准确知道它在哪里,并可以快速返回位置。(如果按照我的经验正确完成操作,通常少于10秒)。

If a Wifi connection is not found(outdoors). 如果未找到Wifi连接(室外)。 You can always drop back to GPS to provide the coordinates. 您始终可以退回到GPS来提供坐标。 Plus Gps is "fastest" outside anyways. 无论如何,Plus Gps是“最快”的。

Checkout these pages: Stackoverflow discussion . 查看以下页面: Stackoverflow讨论 Location Manager Android . 位置管理器Android If you want to get really fancy you can even use the Geocoder Android library to get Location addresses etc in human readable form. 如果您真的想花哨的话,甚至可以使用Geocoder Android库以易于阅读的形式获取位置地址等。

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

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