【发布时间】:2013-09-01 17:56:52
【问题描述】:
我正在使用 Fused Location Provider 开发应用程序。我有个疑问。为了定期获取位置,它使用 requestLocationUpdates()。但它从哪个来源获取位置,无论是从 WIFI 还是 GPS 或网络。在我的应用程序中,只有当 WiFi 开启时,它才会定期获取位置。当 WiFi 处于关闭状态时,它无法获取位置(它应该从 GPS 或网络的其他来源获取位置。但它永远不会获取位置。或者我必须为 GPS 和网络编写侦听器)。我不知道是什么问题。谁能帮帮我。
而且,它是否仅在所有提供商(Wifi、GPS、网络)可用时才有效。
public void checkPlay(){
int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resp == ConnectionResult.SUCCESS) {
locationClient = new LocationClient(this, this, this);
locationClient.connect();
} else {
Toast.makeText(this, "Google Play Service Error " + resp,
Toast.LENGTH_LONG).show();
}
}
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
if (locationClient != null && locationClient.isConnected()) {
locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(100);
locationClient.requestLocationUpdates(locationRequest, this);
}
}
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
try {
if (location != null) {
lat = location.getLatitude();
long = location.getLongitude();
}
} catch (Exception e) {
Log.d(Fots.TAG,
"GpsTrackService.mGpsLocationListener.onLocationChanged", e);
}
}
【问题讨论】:
-
推荐这个可能有帮助wptrafficanalyzer.in/blog/…
-
如何测试位置更新?
-
twntee..我在服务中写 onLocationChanged()。当我登录到应用程序时,该服务将启动并每 1 分钟运行一次服务,并使用“locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);”每 5 秒获取一次位置更新
-
Hai Aravinth,引用的链接使用旧的位置 API。它使用 LocationManager、GeoCoder。但我正在使用使用 GooglePlayServices 的新位置 API(融合位置提供程序)。
-
我遇到了同样的问题,Goole Play Services 版本 3.2.65(及更高版本)可能已经解决了这个问题。你还有这个问题吗?
标签: android google-maps gps google-maps-android-api-2 location-provider