本文整理匯總了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);
}