FusedLocationProvider在没有Wifi的情况下无法正常工作

时间:2016-09-21 08:05:53

标签: java android location google-play-services

我使用GoogleAPIs的FusedLocationProvider来请求位置数据。有时,当我关闭WIFI时,它无法通过GPS接收位置数据。 GoogleApiClient成功连接,我在真实设备上进行测试 - 所以这不应该是问题所在。我的设置如下:

mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(4000);
mLocationRequest.setFastestInterval(2000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setNumUpdates(5);

如果打开并连接WIFI,整个过程非常有效。即使我打开WIFI,获取位置数据,再次关闭它然后再次开始更新位置它正在使用新数据。在我看来,missbehaviour是完全随机的,我不知道为什么会发生这种情况(特别是在夜间关闭设备之后)。我希望它能用GPS获取新的位置数据。顺便说一句,我可以在状态栏中看到GPS图标但我没有收到新数据。 logcat中显示的错误如下:

09-21 09:54:44.547 3947-27505/? W/System.err: java.net.UnknownHostException: Unable to resolve host "www.google.com": No address associated with hostname
09-21 09:54:44.547 3947-27505/? W/System.err:     at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:125)
09-21 09:54:44.547 3947-27505/? W/System.err:     at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
09-21 09:54:44.547 3947-27505/? W/System.err:     at java.net.InetAddress.getAllByName(InetAddress.java:752)
09-21 09:54:44.547 3947-27505/? W/System.err:     at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
09-21 09:54:44.547 3947-27505/? W/System.err:     at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:187)
09-21 09:54:44.547 3947-27505/? W/System.err:     at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:156)
09-21 09:54:44.547 3947-27505/? W/System.err:     at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:98)
09-21 09:54:44.547 3947-27505/? W/System.err:     at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:345)
09-21 09:54:44.547 3947-27505/? W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
09-21 09:54:44.548 3947-27505/? W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
09-21 09:54:44.548 3947-27505/? W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
09-21 09:54:44.548 3947-27505/? W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
09-21 09:54:44.549 3947-27505/? W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)
09-21 09:54:44.549 3947-27505/? W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
09-21 09:54:44.550 3947-27505/? W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
09-21 09:54:44.550 3947-27505/? W/System.err:     at akkl.a(:com.google.android.gms:89)
09-21 09:54:44.550 3947-27505/? W/System.err:     at amcc.run(:com.google.android.gms:289)
09-21 09:54:44.550 3947-27505/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
09-21 09:54:44.550 3947-27505/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
09-21 09:54:44.550 3947-27505/? W/System.err:     at java.lang.Thread.run(Thread.java:761)
09-21 09:54:44.550 3947-27505/? W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
09-21 09:54:44.550 3947-27505/? W/System.err:     at libcore.io.Posix.android_getaddrinfo(Native Method)
09-21 09:54:44.550 3947-27505/? W/System.err:     at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
09-21 09:54:44.550 3947-27505/? W/System.err:     at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:106)
09-21 09:54:44.550 3947-27505/? W/System.err:   ... 19 more

所以我真的需要WIFI至少一次通过GPS获取数据吗?并且有可能像超时一样,所以我可以告诉用户"嘿,你需要Wifi来获取位置数据"?检查网络连接不是一种选择,因为如上所述,它在没有WIFI的情况下工作很多次。

0 个答案:

没有答案