OnLocationChanged callback is never called

前端 未结 14 1402
星月不相逢
星月不相逢 2020-12-01 03:28

I am trying to get the users current location using the LocationManager. I have done a lot of research and can\'t seem to find anyone with the same problem. T

14条回答
  •  -上瘾入骨i
    2020-12-01 03:59

    It looks like you setup should work, since it doesn't, I would make your example as simple as possible in order to troubleshoot. I would make your request look like

    requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
    

    This way you get ALL the updates possible. And comment out the part about getting the last known location. It's not needed yet.

    Then in onLocationChanged(), just have

    Log.v(TAG, "IN ON LOCATION CHANGE, lat=" + latitude + ", lon=" + longitude);
    

    Comment out the rest so that you keep your listener active. This should give you a stream of updates on a real device. On the emulator, you'll need to use DDMS, and you'll get one GPS update each time you press send.

提交回复
热议问题