Android LocationManager Criteria

前端 未结 3 1910
长情又很酷
长情又很酷 2021-01-12 11:18

I need to receive location changes both from Network and GPS providers.

If GPS provider not avaliable or has not location (bad sattelite visibility) I would receive

3条回答
  •  清歌不尽
    2021-01-12 11:40

    Just don't give any criteria, and try to get the best provider:

    LocationManager mgr = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    String best = mgr.getBestProvider(criteria, true);
    //since you are using true as the second parameter, you will only get the best of providers which are enabled.
    Location location = mgr.getLastKnownLocation(best);
    

提交回复
热议问题