How to get current Location in GoogleMap using FusedLocationProviderClient

前端 未结 4 1475
南方客
南方客 2020-11-28 04:33

I want to get periodic (say every 2 minutes) current location updates for this I\'m following official documentation, I wrote this code but its not giving current location u

4条回答
  •  盖世英雄少女心
    2020-11-28 05:28

        private LocationRequest locationRequest;
    
        public class MapsActivity extends FragmentActivity implements LocationListener{
    
        locationRequest = new LocationRequest();
        locationRequest.setInterval(60 * 1000);
        locationRequest.setFastestInterval(15 * 1000);
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    
    
    @Override
    public void onLocationChanged(Location location) {
    
        latitude = location.getLatitude();
        longitude = location.getLongitude();
    
    }
    

    Implement Location change listener and you will be able to override onlocation changed...

提交回复
热议问题