本文整理匯總了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);
}
示例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;
}
}
});
}
示例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();
}
});
}
示例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);
}
示例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();
}
}
});
}
示例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
}
}
示例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();
}
});
}
示例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());
}
示例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);
}
示例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();
}
示例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);
}
}
}
示例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();
}
});
}
示例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());
}
}
};
}
示例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();
}
示例15: LocationProvider
import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
public LocationProvider(Context context) {
this.context = context;
locationProviderClient = LocationServices.getFusedLocationProviderClient(context);
}