1

的工作方式有点困惑。

  1. 如果我将其requestlocationUpdates(LocationManager.GPS_PROVIDER, , );作为位置提供者并测试我的应用程序。我看到,如果我没有启用 gps,它会从网络获取更新,并且当它启用时,它会从 gps 获取更新。如果网络和 gps 提供商自行切换,设置它们发送更新有什么意义?

  2. 第三个参数是如何requestlocationUpdates工作的?我的意思是它说它会改变我设置的距离,但是它如何检测到我已经移动了?

4

2 回答 2

0

You can try with following code

Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);

where Criteria is a class indicating the application criteria for selecting a location provider. Providers maybe ordered according to accuracy, power usage, ability to report altitude, speed, and bearing, and monetary cost.

then

locationManager.requestLocationUpdates(provider,0, 0, new MyLocationListener());

Where second and third parameter are use to so that you can control the frequency at which your listener receives updates with the second and third parameter—the second is the minimum time interval between notifications and the third is the minimum change in distance between notifications—setting both to zero requests location notifications as frequently as possible.

于 2013-03-12T12:01:57.673 回答
0
  1. 请记住,一旦您 requestLocationUpdates(...) 意味着 onLocationChanged(...) 将在启用指定提供程序时触发,您将在 onLocationChanged 方法中获得最新坐标。在检测到任何新位置之前,系统将使用默认位置,即缓存位置或 LastKnownLocation。

  2. 当然,当您当前的位置与之前的位置(缓存位置)不同时,系统会认为您正在移动。

于 2013-03-18T07:46:01.307 回答