Genymotion 的定位请求位置太快
Genymotion's locationing requesting the locations too fast
我使用 Fused location 制作了一个简单的定位服务,我用 真实设备 和 Genymotion 的 android 虚拟设备.
获取位置的 iterval 是 5 秒。
在真实设备上它运行良好,间隔是几乎恰好 5 秒,
检查日志:(onLC 用于 OnLocationChanged)
03-17 11:59:27.115: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:32.189: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:37.259: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:42.171: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:47.215: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:52.240: I/Locationing_GpsService_Test(27147): onLC:Now!
在 Genymotions 虚拟设备上 间隔大约为 1 秒:
03-17 12:10:20.280: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:21.270: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:22.269: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:23.271: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:24.273: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:25.273: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:26.275: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:27.273: I/Locationing_GpsService_Test(2616): onLC:Now!
用于初始化位置请求的代码:
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
有人能帮我看看这是怎么回事吗?
您认为 Fused location
可以在模拟器上运行吗? Fused location
完全是关于融合 mobile/wifi/gps 信号——你期望 Genymotion
模拟 mobile/wifi/gps 以便它向 Fused location
输入一些有意义的数据吗?我不这么认为。
无论如何,如果您查看 setInterval,您会看到:
You may also receive them faster than requested (if other applications are requesting location at a faster interval).
所以设置mLocationRequest.setInterval(5000);
其实没有任何意义
只需添加 mLocationRequest.setFastestInterval(5000);
就可以了,现在 Genymotion 的虚拟设备还以 5 秒为间隔请求位置更新。
Genymotion 会立即获取位置信息,并将其传递给您的应用,因此无需等待,就像在真实设备上一样。它不模拟(或模拟)寻找 GPS 卫星的过程,就像在真正的 GPS 传感器中一样,而且它使用您的 PC 互联网速度,而不是移动 GPRS 或 public Wi-Fi,所以它也得到你的位置几乎立即。 ADB模拟器也是如此。您应该使用真实设备来测试定位服务。
我使用 Fused location 制作了一个简单的定位服务,我用 真实设备 和 Genymotion 的 android 虚拟设备.
获取位置的 iterval 是 5 秒。
在真实设备上它运行良好,间隔是几乎恰好 5 秒, 检查日志:(onLC 用于 OnLocationChanged)
03-17 11:59:27.115: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:32.189: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:37.259: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:42.171: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:47.215: I/Locationing_GpsService_Test(27147): onLC:Now!
03-17 11:59:52.240: I/Locationing_GpsService_Test(27147): onLC:Now!
在 Genymotions 虚拟设备上 间隔大约为 1 秒:
03-17 12:10:20.280: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:21.270: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:22.269: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:23.271: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:24.273: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:25.273: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:26.275: I/Locationing_GpsService_Test(2616): onLC:Now!
03-17 12:10:27.273: I/Locationing_GpsService_Test(2616): onLC:Now!
用于初始化位置请求的代码:
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
有人能帮我看看这是怎么回事吗?
您认为 Fused location
可以在模拟器上运行吗? Fused location
完全是关于融合 mobile/wifi/gps 信号——你期望 Genymotion
模拟 mobile/wifi/gps 以便它向 Fused location
输入一些有意义的数据吗?我不这么认为。
无论如何,如果您查看 setInterval,您会看到:
You may also receive them faster than requested (if other applications are requesting location at a faster interval).
所以设置mLocationRequest.setInterval(5000);
其实没有任何意义
只需添加 mLocationRequest.setFastestInterval(5000);
就可以了,现在 Genymotion 的虚拟设备还以 5 秒为间隔请求位置更新。
Genymotion 会立即获取位置信息,并将其传递给您的应用,因此无需等待,就像在真实设备上一样。它不模拟(或模拟)寻找 GPS 卫星的过程,就像在真正的 GPS 传感器中一样,而且它使用您的 PC 互联网速度,而不是移动 GPRS 或 public Wi-Fi,所以它也得到你的位置几乎立即。 ADB模拟器也是如此。您应该使用真实设备来测试定位服务。