current location is always null

后端 未结 6 1894
独厮守ぢ
独厮守ぢ 2021-02-04 22:39

I am trying to retrieve my current location on the button click in an editbox using gps or network..i have tried all possible methods which i found in tutorials and older posts.

6条回答
  •  长情又很酷
    2021-02-04 22:58

    Another reason for getting null back from locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); would be if your network provider was turned off. On my phone this is toggled via Settings -> Location -> Use wireless networks.

    EDIT:

    You could also try:

    LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
    

    to see if the network provider is enabled or

    LocationManager.getProviders(true)
    

    to return any enabled providers.

    See http://developer.android.com/reference/android/location/LocationManager.htm for more info

提交回复
热议问题