Finding Current Location in android

后端 未结 5 1332
再見小時候
再見小時候 2021-01-24 13:51

I am trying to find current location, and this is my code.

 LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);        
           


        
5条回答
  •  醉话见心
    2021-01-24 14:07

    I think what you meant to do was this

    Location location = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    

    But please note that this will only work if your gps has already grabbed a previous location. So on the emulator you will need to send a location BEFORE this line is called, and on a real device the gps will have to have been activated before the line and have received a location.

提交回复
热议问题