Getting null from 'getLastKnownLocation' on SDK

前端 未结 6 1362
星月不相逢
星月不相逢 2020-12-01 19:52

I have a problem related to the Location API.

I tried the following code:

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SER         


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-01 20:51

    You need the instance Of LocationManager like this:

    First Instance:

       LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    

    Wrong:

    Location loc = getLastKnownLocation(LocationManager.GPS_PROVIDER);
    

    Correct:

    Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    

提交回复
热议问题