本文整理了Java中com.google.android.gms.location.FusedLocationProviderApi.requestLocationUpdates()
方法的一些代码示例,展示了FusedLocationProviderApi.requestLocationUpdates()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FusedLocationProviderApi.requestLocationUpdates()
方法的具体详情如下:
包路径:com.google.android.gms.location.FusedLocationProviderApi
类名称:FusedLocationProviderApi
方法名:requestLocationUpdates
暂无
代码示例来源:origin: commonsguy/cw-omnibus
@SuppressWarnings("MissingPermission")
void requestLocations() {
PendingResult<Status> result=
LocationServices.FusedLocationApi
.requestLocationUpdates(getPlayServices(), request, this);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Toast
.makeText(getActivity(),
R.string.location_req_success_msg,
Toast.LENGTH_LONG)
.show();
} else {
Toast
.makeText(getActivity(), status.getStatusMessage(),
Toast.LENGTH_LONG)
.show();
getActivity().finish();
}
}
});
}
代码示例来源:origin: palaima/DebugDrawer
void startLocationUpdates() {
googleApiClient.connect();
if (connected && locationRequest != null) {
isStarted = true;
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, locationListener);
}
}
代码示例来源:origin: yayaa/LocationManager
@SuppressWarnings("ResourceType")
void requestLocationUpdate() {
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
代码示例来源:origin: smarques84/MockLocationDetector
protected void startLocationUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
代码示例来源:origin: vipulasri/LocationUpdates
protected void startLocationUpdates() {
Log.i(TAG, "Started Location Updates");
//LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mPendingIntent);
}
代码示例来源:origin: safetysystemtechnology/location-tracker-background
protected void startLocationUpdates() {
try {
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
} catch (SecurityException ex) {
}
}
代码示例来源:origin: techyourchance/idocare-android
@Override
public void onConnected(@Nullable Bundle bundle) {
if (isAccessFineLocationPermissionGranted()) {
//noinspection MissingPermission
mFusedLocationProviderApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
} else {
throw new IllegalStateException("required permission wasn't granted");
}
}
代码示例来源:origin: ankitdubey021/GPSTracker
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.i("My Tracker", "Location services connected!.");
if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
fetchLocation(location);
if (location == null) {
if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
}
代码示例来源:origin: WomenWhoCode/WomenWhoCode
@Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "Location services connected.");
Location mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mCurrentLocation == null) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
} else {
mLocationCallback.handleNewLocation(mCurrentLocation);
}
}
代码示例来源:origin: amotzte/android-mock-location-for-development
public void testMock(View view) { // On some version do like this
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
askRunTimePermissions();
return;
}
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
Intent intent = new Intent();
intent.putExtra("lat", String.valueOf(dummyLat));
intent.putExtra("lon", String.valueOf(dummylong));
intent.setAction("send.mock");
sendBroadcast(intent);
} else {
Toast.makeText(this, "Failed - Google play services is not connected", Toast.LENGTH_SHORT).show();
}
}
代码示例来源:origin: klaasnotfound/LocationAssistant
private void requestLocationUpdates() {
if (!googleApiClient.isConnected() || !permissionGranted || !locationRequested) return;
try {
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
updatesRequested = true;
} catch (SecurityException e) {
if (!quiet)
Log.e(getClass().getSimpleName(), "Error while requesting location updates:\n " +
e.toString());
if (listener != null)
listener.onError(ErrorType.RETRIEVAL, "Could not request location updates:\n" +
e.getMessage());
}
}
代码示例来源:origin: lycha/augmented-reality-example
@Override
public void onConnected(Bundle bundle) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
onLocationChangedListener.onLocationChanged(mLastLocation);
}
}
代码示例来源:origin: florent37/RxGps
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter<Status> emitter) {
//noinspection MissingPermission
setupLocationPendingResult(
LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, pendingIntent),
SingleResultCallBack.get(emitter)
);
}
}
代码示例来源:origin: domsu/compass
private void registerForUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, createLocationRequest(), this);
emitLastKnownLocation();
}
代码示例来源:origin: priyankapakhale/GoogleMapsNearbyPlacesDemo
@Override
public void onConnected(@Nullable Bundle bundle) {
locationRequest = new LocationRequest();
locationRequest.setInterval(100);
locationRequest.setFastestInterval(1000);
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION ) == PackageManager.PERMISSION_GRANTED)
{
LocationServices.FusedLocationApi.requestLocationUpdates(client, locationRequest, this);
}
}
代码示例来源:origin: florent37/RxGps
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, FlowableEmitter<Location> emitter) {
locationListener = new RxLocationListener(emitter);
//noinspection MissingPermission
setupLocationPendingResult(
LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, locationListener, looper),
new StatusErrorResultCallBack(emitter)
);
}
代码示例来源:origin: hiteshbpatel/Android_Blog_Projects
@Override
public void onConnected(Bundle bundle) {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
}
代码示例来源:origin: nglauber/dominando_android2
private void iniciarDeteccaoDeLocal() {
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(5 * 1000);
locationRequest.setFastestInterval(1 * 1000);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, locationRequest, this);
}
代码示例来源:origin: offensive-security/nethunter-app
private void startLocationUpdates() {
Log.d(TAG, "in startLocationUpdates");
final LocationRequest lr = LocationRequest.create()
.setExpirationDuration(1000 * 3600 * 2) /*2 hrs*/
.setFastestInterval(100L)
.setInterval(1000L / 2L) /*2 hz updates*/
.setMaxWaitTime(600L)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Log.d(TAG, "Requesting permissions marshmallow");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, lr, locationListener);
}
}
代码示例来源:origin: AnupKumarPanwar/Uber-Like-Cab-Service
@Override
public void onConnected(Bundle bundle) {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
mMap.setTrafficEnabled(true);
mMap.animateCamera(CameraUpdateFactory.zoomTo(18));
// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(0, 0), 18.0f));
mMap.setMyLocationEnabled(false);
}
内容来源于网络,如有侵权,请联系作者删除!