什么是map.setMyLocationEnabled(真)真的 [英] What does map.setMyLocationEnabled(true) really do

查看:2219
本文介绍了什么是map.setMyLocationEnabled(真)真的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置:

  map.setMyLocationEnabled(真)
 

不过,我想知道这到底是什么呢。我所知道的:

  1. 我得到了地图的右上角找到我的按钮
  2. 在我得到了重新地图上的蓝色图标presents我目前的位置

下面是我所关注。我写一个位置感知应用程序,但我关心的电池。在其他地方我的应用程序(通过preferences)我设置了一个LocationManager和监听定位事件,所以我可以登录他们。但是,我的preferences一部分是我得到更新和时间间隔的准确性。

当我关掉我的LocationManager:

  locationManange.removeUpdates(LocationListener的监听器);
 

我预计要关闭位置服务,为整个应用程序。然而,我仍然看到在我的手机显示的应用程序标题栏越来越位置更新的GPS小图标。我知道那是从我设置我的地图视图的事实来了:

  map.setMyLocationEnabled(真正的);
 

我本来以为,如果你没有通过设置LocationManager的设置map.setMyLocationEnabled(真)监听位置更新没有任何作用(即没有我的位置图标或按钮)。然而事实并非如此。

这是否意味着,通过调用map.setMyLocationEnabled(真),谷歌正在建立其自己的设置自己的LocationManager?我真的想叫map.setMyLocationEnabled(真),但它用我的设置位置更新没有任何谷歌正在做的引擎盖下。那可能吗?我错过了什么,在文档?我无法找到有关的准确性或间隔,设置在一个LocationManager当我打电话map.setMyLocationEnabled(真正的)东西。

解决方案
  

这是否意味着,通过调用map.setMyLocationEnabled(真),谷歌正在建立其自己的设置自己的LocationManager?

不完全是。地图V2 <一href="https://developer.android.com/reference/com/google/android/gms/location/LocationClient.html">uses LocationClient 默认情况下。

  

我真的想叫map.setMyLocationEnabled(真),但它用我的设置位置更新没有任何谷歌正在做的引擎盖下。这可能吗?

您可以<一href="https://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html#setLocationSource%28com.google.android.gms.maps.LocationSource%29">use setLocationSource() 以提供自己的位置数据与我的定位层使用。 这里是证明这是一个示例项目。

I am setting:

map.setMyLocationEnabled(true)

But I am wondering what this really does. What I know:

  1. I get a locate me button in the upper right corner of the map
  2. I get a blue icon on the map that represents my current location

Here is my concern. I am writing a location aware app but I am concerned about battery. Elsewhere in my app (via preferences) I set up a LocationManager and listen for location events so I can log them. But part of my preferences is the accuracy at which I get updates and the interval.

When I turn off my LocationManager:

locationManange.removeUpdates(LocationListener listener);

I expect to turn off location services for the entire app. Yet I still see the little GPS icon in my phones header bar indicating the app is getting location updates. I know that is coming from the fact that I set this on my map view:

map.setMyLocationEnabled(true);

I originally thought that if you did not listen for Location updates by setting up a LocationManager that set map.setMyLocationEnabled(true) would have no effect (ie no my location icon, or button). However that is not true.

Does that mean that by calling map.setMyLocationEnabled(true) google is setting up its own LocationManager with its own settings? 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? Did I miss something in the docs? I cannot find anything about the accuracy or interval that is setup on a LocationManager when I call map.setMyLocationEnabled(true).

解决方案

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

Not exactly. Maps V2 uses LocationClient by default.

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?

You can use setLocationSource() to supply your own location data for use with the my-location layer. Here is a sample project demonstrating this.

这篇关于什么是map.setMyLocationEnabled(真)真的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆