android - map.setMyLocationEnabled(true) 的真正作用是什么

标签 android google-maps geolocation google-maps-android-api-2

我正在设置:

map.setMyLocationEnabled(true)

但我想知道这到底是做什么的。我所知道的:

  1. 我在 map 右上角有一个“定位我”按钮
  2. 我在 map 上看到代表我当前位置的蓝色图标

这是我的担忧。我正在编写一个位置感知应用程序,但我担心电池。在我的应用程序的其他地方(通过首选项),我设置了一个 LocationManager 并监听位置事件,以便我可以记录它们。但我的部分偏好是我获得更新的准确性和间隔。

当我关闭 LocationManager 时:

locationManange.removeUpdates(LocationListener listener);

我希望关闭整个应用的定位服务。然而,我仍然在我的手机标题栏中看到小 GPS 图标,表明该应用正在获取位置更新。我知道这是因为我在 map View 上设置了它:

map.setMyLocationEnabled(true);

我最初认为,如果您没有通过设置设置 map.setMyLocationEnabled(true) 的 LocationManager 来监听位置更新,则不会有任何效果(即没有我的位置图标或按钮)。然而事实并非如此。

这是否意味着通过调用 map.setMyLocationEnabled(true) google 正在使用自己的设置设置自己的 LocationManager?我真的很想调用 map.setMyLocationEnabled(true),但让它使用我的位置更新设置,而不是谷歌在幕后所做的任何事情。那可能吗?我错过了文档中的某些内容吗?当我调用 map.setMyLocationEnabled(true) 时,我找不到关于 LocationManager 上设置的准确性或间隔的任何信息。

最佳答案

Does that mean that by calling map.setMyLocationEnabled(true) google is setting up its own LocationManager with its own settings?

不完全是。 map V2 uses LocationClient默认情况下。

I would really like to call map.setMyLocationEnabled(true), but have it use my settings for location updates not whatever google is doing under the hood. Is that possible?

您可以use setLocationSource()提供您自己的位置数据以用于 my-location 图层。 Here is a sample project证明这一点。

关于android - map.setMyLocationEnabled(true) 的真正作用是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519847/

相关文章:

android - phonegap 地理位置总是在超时时失败

javascript - 在 Bootstrap 选项卡上调整大小后,谷歌地图标记不居中

android - 我如何使用领域知识来改进这个算法?呃,重量

java - 为什么在 Java 中使用静态辅助方法不好?

android - 有没有办法在 TabLayout 中的每个选项卡之间添加垂直线

javascript - 如何获取getroute生成的marker的onclick事件

java - 将元素添加到 String、Arraylist 的 Map

javascript - 使用ajax填充谷歌地图标记

android - 所选列表项上的弹出栏

algorithm - 如何对地理数据进行排序以便快速搜索