0

I use the FusedLocationProvider from GoogleAPIs to request location data. Sometimes, when I WIFI is turned off, it is not able to receive location data through GPS. GoogleApiClient gets connected successfully and I test it on a real device - so this shouldn't be the problem. My settings look like this:

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

The whole process works very well if WIFI is turned on and connected. Even if I turn WIFI on, get location data, turn it off again and then start updating location again it is working with new data. The missbehaviour is totally random in my view and I don't know why this happens sometimes (especially after device was turned off during night). I would expect it to use GPS to get new location data. By the way I can see the GPS icon in the status bar but I don't receive new data. The error which is shown in logcat is the following:

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

So do I really need WIFI at least one time to get data via GPS? And is there a possibility like a timeout so I can tell the user "Hey you need Wifi to get location data"? Checking the network connection is not an option because as mentioned above it is working most times without WIFI.

Phil
  • 25
  • 7
  • The error is nothing related with the Fused location.`Unable to resolve host "www.google.com": No address associated with hostname` – Madhukar Hebbar Sep 21 '16 at 09:04
  • It is 100 percent related to the FusedLocationProvider because it only happens when I try to use it. Of course this is because of missing WIFI but the question is why does the FusedLocationProvider need to request google.com there? If I turn WIFI on, request location, turn it off I can get location updates without this error shown above – Phil Sep 21 '16 at 11:02
  • I could imagine the device trying to connect to Google's servers in order to check if there's any location info for any of the Wi-Fi devices that the device can see around it. But that's just a guess and not so relevant for your problem. My other guess is that finding the GPS location just takes more time, or it may even be impossible for example indoors. My third guess is that temporarily turning Wi-Fi on allows the device to determine its rough location which in turn helps finding the GPS location faster (or at all). And of course with that `LocationRequest` you'll anyway get only 5 updates. – Markus Kauppinen Sep 21 '16 at 11:19
  • Mhm the only reason I could imagine is the last one - because I don't change location between the tests with the results "it works" and "it doesn't work" – Phil Sep 21 '16 at 12:58
  • Check this [SO question](http://stackoverflow.com/questions/26200690/fused-location-provider-unexpected-behavior) if it can help you. – KENdi Sep 22 '16 at 07:14
  • Thanks @KENdi but it seems to be a little different. I mean I can receive location updates (which are not the last known location which can be verified with .getTime()) so it is definitely possible but under some circumstances the above mentioned behaviour is happening :/ – Phil Sep 22 '16 at 12:08

0 Answers0