简体   繁体   English

Android 位置提供商 - GPS 还是网络提供商?

[英]Android Location Providers - GPS or Network Provider?

In my application I would like to determine the user's current location.在我的应用程序中,我想确定用户的当前位置。 I do however have a couple of questions in this regard:但是,在这方面我确实有几个问题:

  1. There are different Location Providers, which one is the most accurate?有不同的位置提供者,哪一个是最准确的? The GPS Provider or the Network Provider ? GPS 提供商网络提供商

  2. In how far do those available provider differ?这些可用的提供者在多大程度上不同? How do they function?他们如何 function?

  3. Could you please provide me with some code-snippets or tutorials on how to get started with implementing GPS functionality in my application?您能否为我提供一些代码片段或教程,了解如何开始在我的应用程序中实现 GPS 功能?

There are 3 location providers in Android. Android 中有 3 个位置提供程序。

They are:他们是:

gps –> (GPS, AGPS): Name of the GPS location provider. gps –>(GPS、AGPS): GPS 位置提供商的名称。 This provider determines location using satellites.该提供商使用卫星确定位置。 Depending on conditions, this provider may take a while to return a location fix.根据条件,此提供程序可能需要一段时间才能返回位置修复。 Requires the permission android.permission.ACCESS_FINE_LOCATION.需要权限 android.permission.ACCESS_FINE_LOCATION。

network –> (AGPS, CellID, WiFi MACID): Name of the network location provider. network –> (AGPS, CellID, WiFi MACID):网络位置提供商的名称。 This provider determines location based on availability of cell tower and WiFi access points.该提供商根据手机信号塔和 WiFi 接入点的可用性确定位置。 Results are retrieved by means of a network lookup.通过网络查找检索结果。 Requires either of the permissions android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.需要权限 android.permission.ACCESS_COARSE_LOCATION 或 android.permission.ACCESS_FINE_LOCATION。

passive –> (CellID, WiFi MACID): A special location provider for receiving locations without actually initiating a location fix.被动–>(CellID,WiFi MACID):一个特殊的位置提供程序,用于接收位置而无需实际启动位置修复。 This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself.当其他应用程序或服务请求位置更新时,此提供程序可用于被动接收位置更新,而无需自己实际请求位置。 This provider will return locations generated by other providers.该提供者将返回由其他提供者生成的位置。 Requires the permission android.permission.ACCESS_FINE_LOCATION, although if the GPS is not enabled this provider might only return coarse fixes.需要权限 android.permission.ACCESS_FINE_LOCATION,但如果未启用 GPS,此提供程序可能只会返回粗略的修复。 This is what Android calls these location providers, however, the underlying technologies to make this stuff work is mapped to the specific set of hardware and telco provided capabilities (network service).这就是 Android 所称的这些位置提供程序,但是,使这些东西工作的底层技术映射到特定的硬件集和电信公司提供的功能(网络服务)。

The best way is to use the “network” or “passive” provider first, and then fallback on “gps”, and depending on the task, switch between providers.最好的方法是先使用“网络”或“被动”提供程序,然后回退到“gps”,并根据任务在提供程序之间切换。 This covers all cases, and provides a lowest common denominator service (in the worst case) and great service (in the best case).这涵盖了所有情况,并提供最低公分母服务(在最坏的情况下)和优质的服务(在最好的情况下)。

在此处输入图像描述

Article Reference: Android Location Providers - gps, network, passive By Nazmul Idris文章参考: Android 位置提供程序 - gps,网络,被动作者 Nazmul Idris

Code Reference: https://stackoverflow.com/a/3145655/28557代码参考: https://stackoverflow.com/a/3145655/28557

-----------------------Update----------------------- - - - - - - - - - - - -更新 - - - - - - - - - - - -

Now Android have Fused location provider现在 Android 已融合位置提供程序

The Fused Location Provider intelligently manages the underlying location technology and gives you the best location according to your needs. Fused Location Provider 智能管理底层定位技术,根据您的需求为您提供最佳位置。 It simplifies ways for apps to get the user's current location with improved accuracy and lower power usage它简化了应用程序获取用户当前位置的方式,提高了准确性并降低了功耗

Fused location provider provide three ways to fetch location Fused Location Provider 提供了三种获取位置的方法

  1. Last Location: Use when you want to know current location once.最后位置:当您想知道当前位置一次时使用。
  2. Request Location using Listener: Use when application is on screen / frontend and require continues location.使用监听器请求位置:当应用程序在屏幕/前端并需要继续位置时使用。
  3. Request Location using Pending Intent: Use when application in background and require continues location.使用待定意图请求位置:在后台应用程序并需要继续位置时使用。

References:参考:

Official site: http://developer.android.com/google/play-services/location.html官方网站: http://developer.android.com/google/play-services/location.html

Fused location provider example: GIT: https://github.com/kpbird/fused-location-provider-example融合位置提供程序示例:GIT: https://github.com/kpbird/fused-location-provider-example

http://blog.lemberg.co.uk/fused-location-provider http://blog.lemberg.co.uk/fused-location-provider

-------------------------------------------------------- -------------------------------------------------- ------

GPS is generally more accurate than network but sometimes GPS is not available, therefore you might need to switch between the two. GPS 通常比网络更准确,但有时 GPS 不可用,因此您可能需要在两者之间切换。

A good start might be to look at the android dev site.一个好的开始可能是查看 android 开发站点。 They had a section dedicated to determining user location and it has all the code samples you need.他们有一个专门用于确定用户位置的部分,其中包含您需要的所有代码示例。

http://developer.android.com/guide/topics/location/obtaining-user-location.html http://developer.android.com/guide/topics/location/obtaining-user-location.html

There are some great answers mentioned here.这里提到了一些很棒的答案。 Another approach you could take would be to use some free SDKs available online like Atooma, tranql and Neura, that can be integrated with your Android application (it takes less than 20 min to integrate).您可以采取的另一种方法是使用一些在线提供的免费 SDK,例如 Atooma、tranql 和 Neura,它们可以与您的 Android 应用程序集成(集成时间不到 20 分钟)。 Along with giving you the accurate location of your user, it can also give you good insights about your user's activities.除了为您提供用户的准确位置外,它还可以让您深入了解用户的活动。 Also, some of them consume less than 1% of your battery此外,其中一些消耗的电池电量不到 1%

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

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