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 cellular network which 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 > > wireless network locations if initially disabled. So I know for sure > > that the listener is registered correctly. It just never gets an > > onLocationChanged call. > > > /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 wireless network updates 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 > > > network location 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 void onLocationChanged(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