Android requestLocationUpdates with GPS null

前端 未结 3 1494
盖世英雄少女心
盖世英雄少女心 2021-01-24 00:22
private void getLocation(){
    locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
    List providers = locationM         


        
3条回答
  •  鱼传尺愫
    2021-01-24 00:57

    getLastKnownLocation() frequently returns null. This is perfectly normal. You only use getLastKnownLocation():

    • as an optimization, to avoid having to wait for a location fix, or
    • if you can live without the location data

    Otherwise, you need to postpone your HTTP GET request until you get a location given to you in onLocationChanged(). Bear in mind that you may never get a location fix.

    The proper use of LocationManager is covered in the documentation.

提交回复
热议问题