Hi Geoff, Thanks for your valuable comments - I am relieved that it is not just me going crazy (:
I will be logging WIFI status and asking my users to enable WIFI if they have problems. I will also log the phone model. Will let you know when I get some more data. Cheers, Michael. On Dec 1, 12:52 am, Funksta <geoff.sim...@gmail.com> wrote: > Ok, I turned on my wifi connection, and now it got the location. I > then turned off my wifi connection and it still works. So I suspect > that by enabling wifi, it somehow allowed the network location to get > cached. Why doesn't it get set when I'm on 3G (or other cell based) > network connections? > > -Geoff > > On Nov 30, 4:30 pm, Funksta <geoff.sim...@gmail.com> wrote: > > > > > I have also noticed this same problem. When I register just the > > NETWORK_PROVIDER for updates, I never see them come in. When I try to > > use getLastKnownLocation(NETWORK), I get a null location. It seems > > like thenetworkprovider just isn't working on my phone. I have > > checked my settings and stopped/started thenetworklocation. > > > I have a MyTouch 3G that recently was upgraded to 2.2.1 > > > Is this a bug just on my phone? Is it a 2.2.1 problem? Somebody please > > help illuminate the situation. > > > I can register for updates with GPS fine, it's justnetworkthat has > > the problem. > > > -Geoff > > > On Nov 30, 2:53 pm, ip332 <iprile...@gmail.com> wrote: > > > > IMHO getProvider(LocationManager.NETWORK_PROVIDER) should return null > > > only in two cases: > > > 1. AIRPLANE mode. > > > 2. In case of GSM phone when SIM card is missing and WiFI is disabled > > > However I tested both cases on Milestone phone (Android 2.1-update1) > > > and always got some not-null result :( > > > The only possibility left is that user uses "hacked" phone, i.e. some > > > app which disablesNetworkprovider or LocationService removed at > > > all. > > > Mistery :) > > > > On Nov 30, 2:01 pm,michael<michael.d.peder...@googlemail.com> wrote: > > > > > Hi again Igor, > > > > > Thanks for your excellent suggestions, I will work on it over the next > > > > couple of days. > > > > > As another curiosity, I am experiencing a very small number of cases > > > > where LocationManager.getProvider(LocationManager.NETWORK_PROVIDER) > > > > returns null. Apparently some phones do not have this capability. > > > > > Best, > > > >Michael. > > > > > On Nov 30, 7:57 pm, ip332 <iprile...@gmail.com> wrote: > > > > > > One more thing: check how and when do you remove listener. > > > > > > On Nov 30, 11:52 am, ip332 <iprile...@gmail.com> wrote: > > > > > > >Michael > > > > > > > Here are some suggestions: > > > > > > 1. Additional logging: mCoarseLocationListener details, WiFi status, > > > > > > cell signal status (may be in those 5% cases users don't have any > > > > > > signal?) > > > > > > 2. Get details from users about phone models, running applications > > > > > > and > > > > > > Android versions. Recently I found interesting "feature" on Motorola > > > > > > phone: sensors do not report events unless the values have been > > > > > > changed - this is a violation of the Android API. May be somewhat > > > > > > similar happens with respect to thenetworklocation on some phones. > > > > > > 3. Add "listener restart" logic after a certain timeout, i.e. if you > > > > > > didn't getonLocationChanged() after a certain time stop the > > > > > > listener, > > > > > > create and start it again. > > > > > > 4. Get Android source code and study the LocationManager hierarchy. > > > > > > Probably the most complicated approach but I would start from here. > > > > > > > Best regards > > > > > > Igor > > > > > > > On Nov 30, 3:07 am,michael<michael.d.peder...@googlemail.com> wrote: > > > > > > > > Hi Igor, > > > > > > > > Thanks for your reply, it is much appreciated. Thanks also for > > > > > > > pointing out the issues with the code I provided. However, this > > > > > > > was > > > > > > > merely a stripped-down outline of what I am doing. The use of > > > > > > > mCoarseLocationListener is a type from the strip-down process, > > > > > > > and I > > > > > > > agree that the LocationProvider variable is not necessary. > > > > > > > > However, the problem remains that while the code works fine in > > > > > > > 95% of > > > > > > > cases, there are still 5% of cases where I never get a call to > > > > > > >onLocationChanged. Any suggestions as to why this is the case would > > > > > > > still be much appreciated. > > > > > > > > Best, > > > > > > >Michael. > > > > > > > > On Nov 30, 12:29 am, ip332 <iprile...@gmail.com> wrote: > > > > > > > > >Michael, > > > > > > > > > According to Android documentation the following call > > > > > > > > locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, > > > > > > > > 0, 0, this); > > > > > > > > requests updates from WiFi or cellularnetworkwhich means you > > > > > > > > should > > > > > > > > get some update (from cell tower) even if WiFi location is not > > > > > > > > available. However, I've seen cases when Google map application > > > > > > > > failed > > > > > > > > to set map to "MyLocation" for several minutes while driving on > > > > > > > > a > > > > > > > > freeway. > > > > > > > > > Back to your code. I think you need to replace > > > > > > > > getLastKnownLocation(mCoarseLocationProvider) with > > > > > > > > getLastKnownLocation(LocationManager.NETWORK_PROVIDER) - it is > > > > > > > > not > > > > > > > > clear where do you get mCoarseLocationProvider. > > > > > > > > Also you don't need to use LocationProvider variable in your > > > > > > > > code > > > > > > > > fragment: > > > > > > > > public MyLocationListener() { > > > > > > > > mLocMan = > > > > > > > > (LocationManager)getSystemService(Context.LOCATION_SERVICE); > > > > > > > > > if > > > > > > > > (mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) > > > > > > > > != > > > > > > > > null) { > > > > > > > > mCurrentLocation = > > > > > > > > mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); > > > > > > > > } > > > > > > > > > > > > > > > > > mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, > > > > > > > > 0, 0, > > > > > > > > this); > > > > > > > > } > > > > > > > > > Check the following link which has a lot of useful > > > > > > > > suggestions:http://developer.android.com/guide/topics/location/obtaining-user-loc... > > > > > > > > > Bets regards > > > > > > > > Igor > > > > > > > > > On Nov 29, 2:44 pm,michael<michael.d.peder...@googlemail.com> > > > > > > > > wrote: > > > > > > > > > > Let me also add that the location listener does sometimes get > > > > > > > > > calls to > > > > > > > > > onProviderEnabled -- this happens after asking the user to > > > > > > > > > enable > > > > > > > > > wirelessnetworklocations if initially disabled. So I know for > > > > > > > > > sure > > > > > > > > > that the listener is registered correctly. It just never gets > > > > > > > > > an > > > > > > > > >onLocationChangedcall. > > > > > > > > > > /Michael. > > > > > > > > > > On Nov 29, 10:10 pm,michael<michael.d.peder...@googlemail.com> > > > > > > > > > wrote: > > > > > > > > > > > Hi folks, > > > > > > > > > > > I have a location listener running in a foreground service. > > > > > > > > > > The > > > > > > > > > > listener registers for wirelessnetworkupdates in its > > > > > > > > > > constructor. In > > > > > > > > > > the majority of cases, location updates are received as > > > > > > > > > > expected. > > > > > > > > > > > However, log entries from the live app show that for about > > > > > > > > > > 5% of my > > > > > > > > > > users, location updates are never received even though > > > > > > > > > > wireless > > > > > > > > > >networklocation is enabled on the phone (I check this > > > > > > > > > >through the > > > > > > > > > > LocationManager.isProviderEnabled method). That > > > > > > > > > > is,onLocationChanged > > > > > > > > > > is never called, at least not within say 20 minutes of > > > > > > > > > > registering the > > > > > > > > > > listener. > > > > > > > > > > > Does anybody have any idea why this might be? Are there > > > > > > > > > > cases, or > > > > > > > > > > certain geographic areas, where you would not expect > > > > > > > > > > wireless > > > > > > > > > > locations to be available? > > > > > > > > > > > A stripped-down outline of the location listener code is > > > > > > > > > > shown below: > > > > > > > > > > > class MyLocationListener extends LocationListener { > > > > > > > > > > private Location mLocation = null; > > > > > > > > > > > public MyLocationListener() { > > > > > > > > > > mLocMan = (LocationManager) > > > > > > > > > > getSystemService(Context.LOCATION_SERVICE); > > > > > > > > > > > if > > > > > > > > > > (mLocMan.getLastKnownLocation(mCoarseLocationProvider) != > > > > > > > > > > null) { > > > > > > > > > > mCurrentLocation = > > > > > > > > > > mLocMan.getLastKnownLocation(mCoarseLocationProvider); > > > > > > > > > > } > > > > > > > > > > > LocationProvider lp = > > > > > > > > > > mLocMan.getProvider(LocationManager.NETWORK_PROVIDER); > > > > > > > > > > mLocMan.requestLocationUpdates(lp.getName(), 0, 0, > > > > > > > > > > this); > > > > > > > > > > } > > > > > > > > > > > public voidonLocationChanged(Location loc) { > > > > > > > > > > mLocation = loc; > > > > > > > > > > } > > > > > > > > > > > } > > > > > > > > > > > I verify through flurry logs that the "network" location > > > > > > > > > > provider is > > > > > > > > > > indeed obtained and enabled, and that mLocation == null > > > > > > > > > > after about 20 > > > > > > > > > > minutes. > > > > > > > > > > > Any suggestions would be enormously appreciated. I am > > > > > > > > > > running out of > > > > > > > > > > ideas for how to fix this, and I cannot replicate the issue > > > > > > > > > > on my own > > > > > > > > > > test devices. > > > > > > > > > > > Cheers, > > > > > > > > > >Michael.- Hide quoted text - > > > > > > > > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en