我正在设置:
map.setMyLocationEnabled(true)
但我想知道这到底是做什么的。我所知道的:
- 我在 map 右上角有一个“定位我”按钮
- 我在 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/