當前位置: 首頁>>代碼示例>>Java>>正文


Java LocationServices.getFusedLocationProviderClient方法代碼示例

本文整理匯總了Java中com.google.android.gms.location.LocationServices.getFusedLocationProviderClient方法的典型用法代碼示例。如果您正苦於以下問題:Java LocationServices.getFusedLocationProviderClient方法的具體用法?Java LocationServices.getFusedLocationProviderClient怎麽用?Java LocationServices.getFusedLocationProviderClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.gms.location.LocationServices的用法示例。


在下文中一共展示了LocationServices.getFusedLocationProviderClient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(R.string.title_settings);

    // start location services, including permissions checks, etc.
    context = this;
    preferences = PreferenceManager.getDefaultSharedPreferences(context);
    useGPS = preferences.getBoolean("use_device_location", false);
    locUpdates = false;
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
    mSettingsClient = LocationServices.getSettingsClient(context);
    createLocationCallback();
    createLocationRequest();
    buildLocationSettingsRequest();
    settingsFragment = (SettingsFragment) getFragmentManager().findFragmentById(R.id.fragmentSettings);
}
 
開發者ID:MTBehnke,項目名稱:NightSkyGuide,代碼行數:21,代碼來源:SettingsActivity.java

示例2: LocationRepository

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
public LocationRepository(Activity activity, GoogleApiClient mGoogleApiClient) {
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(activity);
    this.mGoogleApiClient = mGoogleApiClient;
    mFusedLocationClient.getLastLocation()
            .addOnSuccessListener(activity, new OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location location) {
                    if (location != null) {
                        userLocation = location;
                        publishSubject.onNext(userLocation);

                        //addOverlay(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()));
                        //mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

                    } else {
                        userLocation = null;
                    }
                }
            });
}
 
開發者ID:aliumujib,項目名稱:Nibo,代碼行數:21,代碼來源:LocationRepository.java

示例3: getCurPos

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
private void getCurPos () {
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    mFusedLocationClient.getLastLocation()
            .addOnSuccessListener(this, new OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location location) {
                    // Got last known location. In some rare situations this can be null.
                    if (location != null) {
                        start = new LatLng(location.getLatitude(), location.getLongitude());
                        if (info == null)
                            info = getAddress(MapsActivity2.this, location.getLatitude(), location.getLongitude());
                        moveToPosition();
                    }
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(MapsActivity2.this, "Check Your GPS or network", Toast.LENGTH_SHORT).show();
                }
            });
}
 
開發者ID:LewisVo,項目名稱:Overkill,代碼行數:23,代碼來源:MapsActivity2.java

示例4: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
public void onCreate() {
    Log.i(LOGSERVICE, "In onCreate");
    super.onCreate();
        
    // Build GoogleApiClient
    buildGoogleApiClient();
        
    // Firebase Authorization
    mAuth = FirebaseAuth.getInstance();
    mUserManager = new UserManager();
        
    // Set User event listener
    setUserEventListener();
    mUserManager.getUser(mAuth.getCurrentUser().getUid(), new IGetUserListener() {
        @Override
        public void onGetSingleUser(User retrievedUser) {
            mUser = retrievedUser;
        }
        @Override
        public void onFailedSingleUser() {
        }
    });
        
    mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
}
 
開發者ID:panzerama,項目名稱:Dispatch,代碼行數:27,代碼來源:LocationUpdaterService.java

示例5: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start_page04);

    get_location = (Button) findViewById(R.id.get_location);

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

    get_location.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!checkPermissions()) {
                requestPermissions();
            } else {
                getLastLocation();
            }
        }
    });
}
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:21,代碼來源:StartPage04.java

示例6: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // set default values in the app's SharedPreferences if never changed
    // note - does not reset preferences back to default values if previously changed
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // start location services, including permissions checks, etc.
    context = this;
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    //preferences.edit().remove("multi_pref_constellation").apply();   //used to clear existing preference if required
    useGPS = preferences.getBoolean("use_device_location", false);
    locUpdates = false;
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
    mSettingsClient = LocationServices.getSettingsClient(context);
    createLocationCallback();
    createLocationRequest();
    buildLocationSettingsRequest();

    if (savedInstanceState == null) {
        // create DSObjectsFragment
        dsObjectsFragment = new DSObjectsFragment();

        // add the fragment to the FrameLayout
        FragmentTransaction transaction =
                getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.fragmentContainer, dsObjectsFragment);
        transaction.commit();  // display DSObjectsFragment
    }
}
 
開發者ID:MTBehnke,項目名稱:NightSkyGuide,代碼行數:35,代碼來源:MainActivity.java

示例7: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
/**
 * Saving instant state for every action
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_habit_events);

    Bundle extras = getIntent().getExtras();
    if (extras!=null){
        if (extras.containsKey(HabitHistoryActivity.EXTRA_EVENT_SERIAL)){
            event = (HabitEvent) extras.getSerializable(HabitHistoryActivity.EXTRA_EVENT_SERIAL);
            position = (int) extras.getSerializable(HabitHistoryActivity.EXTRA_EVENT_POSITION);
        }
    }
    if (event==null){
        finish();
        return;
    }

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);


    comment = (TextView) findViewById(R.id.eventComment);
    comment.setText(event.getComment());
    image = (ImageView) findViewById(R.id.eventPhoto);
    eventdate = (TextView) findViewById(R.id.eventDate);
    eventdate.setText(dateFormat.format(event.getDate()));
    toolbar = (Toolbar) findViewById(R.id.actionbar);
    toolbar.setTitle("Habit Event");
    toolbar.setNavigationIcon(R.drawable.ic_close_button);
    setSupportActionBar(toolbar);

    if (event.getEncodedPhoto()!=null){
        imageDisplay = ImageController.base64ToImage(event.getEncodedPhoto());
        image.setImageBitmap(imageDisplay);
    }else{
        imageDisplay = null;
    }

    image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dispatchTakePictureIntent();
        }
    });
}
 
開發者ID:CMPUT301F17T09,項目名稱:GoalsAndHabits,代碼行數:49,代碼來源:ViewEventActivity.java

示例8: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    Log.d("LocationService", "onCreate");

    manager = new DataProviderManager();
    manager.addObserver(this);

    mClient = LocationServices.getFusedLocationProviderClient(this);

    //implementation of the location update callback
    //what happens when the service receives the user location is defined here
    callback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            lastLocation = locationResult.getLastLocation();
            Log.d("LocationService", "new location received");
            notifyUIOfNewPosition();
            //update the location providers with the new location
            manager.onLocationChanged(lastLocation);

            if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(getString(R.string.pref_active_key), getResources().getBoolean(R.bool.pref_active_default))
                    && manager.isCameraNearerThan(Float.parseFloat(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString(getString(R.string.pref_radius_key), getString(R.string.pref_radius_default))), lastLocation)) {
                enableCameraWarning();
            } else {
                disableCameraWarning();
            }

        }
    };

    //build the notification for @see {@link #startForeground()} to keep the service from being killed
    startForeground(CAMERA_FOREGROUND_SERVICE_NOTIFICATION_ID, buildForegroundNotification());
}
 
開發者ID:Jugendhackt,項目名稱:Camera-warner,代碼行數:36,代碼來源:LocationService.java

示例9: MappaGoogle

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
/**
 * Costruttore della classe. Inizializza i componenti della mappa.
 */
public MappaGoogle(MainActivity a) {
    mMainActivity = a;

    // inizializza la mappa
    final SupportMapFragment mapFragment =
            (SupportMapFragment) a.getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);


    // verifica se si dispone dell'autorizzazione alla posizione, ed eventualmente la chiede.
    // Per le versioni di android precedenti a M, il permesso è confermato automaticamente
    if (ActivityCompat.checkSelfPermission(mMainActivity,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
     && ActivityCompat.checkSelfPermission(mMainActivity,
            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
     && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            mMainActivity.requestPermissions(new String[]
                            {android.Manifest.permission.ACCESS_FINE_LOCATION,
                             android.Manifest.permission.ACCESS_COARSE_LOCATION},
                    PERMISSION_CODE);

    } else {
        mGeoPermessoDisponibile = true;
    }

    // inizializza i servizi di localizzazione google
    mLocationProvider = LocationServices.getFusedLocationProviderClient(mMainActivity);
}
 
開發者ID:IelloDevTeam,項目名稱:IelloAndroidAdminApp,代碼行數:33,代碼來源:MappaGoogle.java

示例10: initialize

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
public static void initialize(@NonNull Activity activity) {
    Log.v(TAG, "Initializing with context: " + activity);
    AndroidLocationProvider instance = getInstance();
    instance.activity = activity;
    instance.fusedLocationClient = LocationServices.getFusedLocationProviderClient(activity);
    instance.setupLocationService();
}
 
開發者ID:neXenio,項目名稱:BLE-Indoor-Positioning,代碼行數:8,代碼來源:AndroidLocationProvider.java

示例11: setupLocationClient

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
public void setupLocationClient(Context context) {
    if(locationClient == null) {
        if(ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            locationClient = LocationServices.getFusedLocationProviderClient(context);
        }
    }
}
 
開發者ID:jpelgrom,項目名稱:Movie-Notifier-Android,代碼行數:8,代碼來源:LocationUtil.java

示例12: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
/**
 * On create, check if the user has location enabled.
 * Obtain the MapFragment and get notified when the map is ready to be used.
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    // Obtain the MapFragment and get notified when the map is ready to be used.
    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    options = (Button) findViewById(R.id.map_options);
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

    try {
        toDisplayAL = (ArrayList<Markers>) getIntent().getExtras().getSerializable("toDisplay");
    } catch (Exception e) {
        // no events to display
    }

    // If GPS (location) is not enabled, User is sent to the settings to turn it on!
    service = (LocationManager) getSystemService(LOCATION_SERVICE);
    boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
    if (!enabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    } else {
        getDeviceLoc();
    }

    options.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
}
 
開發者ID:CMPUT301F17T23,項目名稱:routineKeen,代碼行數:41,代碼來源:MapsActivity.java

示例13: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mLocationButton = (Button) findViewById(R.id.button_location);
    mLocationTextView = (TextView) findViewById(R.id.textview_location);
    mAndroidImageView = (ImageView) findViewById(R.id.imageview_android);


    // Initialize the FusedLocationClient.
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(
            this);

    // Set up the animation.
    mRotateAnim = (AnimatorSet) AnimatorInflater.loadAnimator
            (this, R.animator.rotate);
    mRotateAnim.setTarget(mAndroidImageView);

    // Restore the state if the activity is recreated.
    if (savedInstanceState != null) {
        mTrackingLocation = savedInstanceState.getBoolean(
                TRACKING_LOCATION_KEY);
    }

    // Set the listener for the location button.
    mLocationButton.setOnClickListener(new View.OnClickListener() {
        /**
         * Toggle the tracking state.
         * @param v The track location button.
         */
        @Override
        public void onClick(View v) {
            if (!mTrackingLocation) {
                startTrackingLocation();
                mTrackingLocation = true;
            } else {
                stopTrackingLocation();
                mTrackingLocation = false;
            }
        }
    });

    // Initialize the location callbacks.
    mLocationCallback = new LocationCallback() {
        /**
         * This is the callback that is triggered when the
         * FusedLocationClient updates your location.
         * @param locationResult The result containing the device location.
         */
        @Override
        public void onLocationResult(LocationResult locationResult) {
            // If tracking is turned on, reverse geocode into an address
            if (mTrackingLocation) {
                new FetchAddressTask().execute(locationResult
                        .getLastLocation());
            }
        }
    };
}
 
開發者ID:ngamolsky,項目名稱:WalkMyAndroid-Location,代碼行數:61,代碼來源:MainActivity.java

示例14: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    lsf = new LoadingScreenFragment();
    hf = new FirstHintFragment();

    SupportMapFragment mapFragment =
            (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
            .add(R.id.hint_cont, lsf)
            .show(lsf)
            .commit();


    mRequestingLocationUpdates = false;
    mLastUpdateTime = "";

    // Update values using data stored in the Bundle.
    updateValuesFromBundle(savedInstanceState);

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    mSettingsClient = LocationServices.getSettingsClient(this);

    // Kick off the process of building the LocationCallback, LocationRequest, and
    // LocationSettingsRequest objects.
    createLocationCallback();
    createLocationRequest();
    buildLocationSettingsRequest();

    isLocationEnabled = false;

    mLocationPermissionGranted = checkPermissions();
    if(!mLocationPermissionGranted) {
        requestPermissions();
    } else {
        startLocationUpdates();
    }

    LanguageManager.languageManagement(this);

    keepScreenOn();
}
 
開發者ID:Augugrumi,項目名稱:SpaceRace,代碼行數:49,代碼來源:MapActivity.java

示例15: LocationProvider

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
public LocationProvider(Context context) {
  this.context = context;
  locationProviderClient = LocationServices.getFusedLocationProviderClient(context);
}
 
開發者ID:Arjun-sna,項目名稱:LocationAware,代碼行數:5,代碼來源:LocationProvider.java


注:本文中的com.google.android.gms.location.LocationServices.getFusedLocationProviderClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。