本文整理汇总了Java中com.google.android.gms.location.LocationRequest类的典型用法代码示例。如果您正苦于以下问题:Java LocationRequest类的具体用法?Java LocationRequest怎么用?Java LocationRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocationRequest类属于com.google.android.gms.location包,在下文中一共展示了LocationRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onConnected
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
//Make request to get the users location
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if (ContextCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
MapStateManager mapStateManager = new MapStateManager(this);
mMap.setMapType(mapStateManager.getMapType());
Log.i(TAG, "onConnected: Current location and saved maptype set!");
}
示例2: displayLocationSettingsRequest
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
public void displayLocationSettingsRequest(final Activity activity) {
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
.addApi(LocationServices.API).build();
googleApiClient.connect();
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(mAccuracy);
locationRequest.setInterval(mInterval);
locationRequest.setFastestInterval(mInterval / 2);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
builder.setAlwaysShow(false);
final PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(new LocationResultCallback(activity));
}
示例3: onConnected
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.d(TAG, "Google API client connected");
// String locationProvider = LocationManager.GPS_PROVIDER;
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5000);
mLocationRequest.setFastestInterval(500);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// We should have permission as we ask for it at startup.
} else {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
}
示例4: onCreate
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (servicesAvailable()) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(UPDATE_INTERVAL_MS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTEVAL_MS);
}
}
示例5: requestLocationRequestUpdates
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@NonNull
@RequiresPermission(
anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" +
".ACCESS_FINE_LOCATION"}
)
public Observable<LocationResult> requestLocationRequestUpdates(LocationRequest request) {
return ObservableTask.create(callback -> {
LocationCallback resultCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult result) {
super.onLocationResult(result);
callback.onNext(result);
}
};
callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback));
return client.requestLocationUpdates(request, resultCallback, null);
});
}
示例6: onLocationPermissionGranted
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@Override
protected void onLocationPermissionGranted() {
mockModeToggleButton.setChecked(true);
final LocationRequest locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(2000);
updatedLocationSubscription = locationProvider
.getUpdatedLocation(locationRequest)
.map(new LocationToStringFunc())
.map(new Func1<String, String>() {
int count = 0;
@Override
public String call(String s) {
return s + " " + count++;
}
})
.subscribe(new DisplayTextOnViewAction(updatedLocationView));
}
示例7: onConnected
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
mRequest = LocationRequest.create();
//TODO: 変数
mRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
.setFastestInterval(1000)
.setInterval(3000);
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mClient, mRequest, this);
}
示例8: startLocationScan
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
private void startLocationScan() {
RxLocation rxLocation = new RxLocation(this);
LocationRequest locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(TimeUnit.SECONDS.toMillis(5));
rxLocationObserver = rxLocation.location()
.updates(locationRequest)
.subscribeOn(Schedulers.io())
.flatMap(location -> rxLocation.geocoding().fromLocation(location).toObservable())
.observeOn(Schedulers.io())
.subscribeWith(new DisposableObserver<Address>() {
@Override public void onNext(Address address) {
boolean isLocationsEnabled = App.INSTANCE.getSharedPreferences().isLocationsEnabled();
if (isLocationsEnabled) {
mOWDevice.setGpsLocation(address);
} else if (rxLocationObserver != null) {
rxLocationObserver.dispose();
}
}
@Override public void onError(Throwable e) {
Log.e(TAG, "onError: error retreiving location", e);
}
@Override public void onComplete() {
Log.d(TAG, "onComplete: ");
}
});
}
示例9: startLocationUpdate
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
private void startLocationUpdate() {
long fastInterval = interval / 2;
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(interval);
mLocationRequest.setFastestInterval(fastInterval);
if (Geolocation.LEVEL_EXACT.equals(this.level))
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
else if (Geolocation.LEVEL_BUILDING.equals(this.level))
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
else
mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
示例10: onConnected
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
long interval = 100L;
long fastInterval = interval / 2;
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(interval);
mLocationRequest.setFastestInterval(fastInterval);
if (Geolocation.LEVEL_EXACT.equals(this.level))
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
else if (Geolocation.LEVEL_BUILDING.equals(this.level))
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
else
mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
LocationServices.FusedLocationApi.requestLocationUpdates(this.mGoogleApiClient, mLocationRequest, this);
}
示例11: getLocation
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
private void getLocation() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.enableAutoManage(this, this)
.build();
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10 * 1000)
.setFastestInterval(1 * 1000);
}
示例12: requestLocationAndWeather
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@SuppressWarnings("MissingPermission")
private void requestLocationAndWeather() {
Log.d(TAG, "requesting location");
RxLocation rxLocation = new RxLocation(getApplicationContext());
LocationRequest locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setNumUpdates(1);
rxLocation.location().updates(locationRequest)
.flatMap(location -> {
Log.d(TAG, "requesting weather");
String key = "abf1b0eed723ba91680f088d90290e6a";
return mDarkSkyApi.forecast(key, location.getLatitude(), location.getLongitude())
.subscribeOn(Schedulers.io());
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(weatherDataJson -> {
String currentWeather = weatherDataJson.get("currently").getAsJsonObject()
.get("summary").getAsString();
mTextView.setText(currentWeather);
});
}
示例13: onConnected
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@Override
public void onConnected(Bundle bundle) {
Toast.makeText(this, "onConnected", Toast.LENGTH_SHORT).show();
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
//mLocationRequest.setSmallestDisplacement(0.1F);
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) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
示例14: setLocationPriority
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@ReactMethod
public void setLocationPriority(int mLocationPriority) {
switch (mLocationPriority) {
case 0:
this.mLocationPriority = LocationRequest.PRIORITY_HIGH_ACCURACY;
break;
case 1:
this.mLocationPriority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
break;
case 2:
this.mLocationPriority = LocationRequest.PRIORITY_LOW_POWER;
break;
case 3:
this.mLocationPriority = LocationRequest.PRIORITY_NO_POWER;
break;
}
}
示例15: onConnected
import com.google.android.gms.location.LocationRequest; //导入依赖的package包/类
@Override
public void onConnected(Bundle bundle) {
//inicializa list view
adapter=new ArrayAdapter<Location>(this, android.R.layout.simple_list_item_1, data);
setListAdapter(adapter);
//define requisicao para obter localizacao
//objeto define quantos updates serao necessarios
//deadline para desistir se nao conseguir obter location
//intervalo
//otimizacao de energia, caso aplicavel
locationRequest = new LocationRequest()
.setNumUpdates(5)
.setExpirationDuration(60000)
.setInterval(1000)
.setPriority(LocationRequest.PRIORITY_LOW_POWER);
LocationSettingsRequest.Builder b = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(playServices, b.build());
result.setResultCallback(this);
}