本文整理汇总了Java中com.google.android.gms.location.LocationRequest.create方法的典型用法代码示例。如果您正苦于以下问题:Java LocationRequest.create方法的具体用法?Java LocationRequest.create怎么用?Java LocationRequest.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.location.LocationRequest
的用法示例。
在下文中一共展示了LocationRequest.create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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);
}
}
示例3: 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);
}
示例4: requestLocationUpdates
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
@Override
public void requestLocationUpdates() {
LocationRequest request = LocationRequest.create();
if (interval != null) {
request.setInterval(interval);
}
if (fastestInterval != null) {
request.setFastestInterval(fastestInterval);
}
if (smallestDisplacement != null) {
request.setSmallestDisplacement(smallestDisplacement);
}
updateRequestPriority(request);
if (googleApiClient.isConnected()) {
//noinspection MissingPermission
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, this);
}
}
示例5: startGps
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
public void startGps() {
mUpdatesRequested = true;
mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(PERIOD);
mLocationRequest.setFastestInterval(PERIOD);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// check Internet connection
mLocationClient = new GoogleApiClient.Builder(getApplication())
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
if (mLocationClient != null)
mLocationClient.connect();
}
示例6: onConnected
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
@SuppressWarnings("MissingPermission")
@Override
public void onConnected(@Nullable Bundle bundle) {
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(1000); // Intervals millis
mLocationRequest.setFastestInterval(500); //If avaible sooner
if (!isPermissionGranted(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
return;
}
if (!checkGPSisOpen()) {
Toast.makeText(this, "Enable location services for accurate data.", Toast.LENGTH_SHORT)
.show();
Intent viewIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(viewIntent);
} else {
LocationServices.FusedLocationApi
.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
getCoords(LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient));
}
}
示例7: findImage
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
private void findImage() {
LocationRequest request = LocationRequest.create();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setNumUpdates(1);
request.setInterval(0);
try {
LocationServices.FusedLocationApi.requestLocationUpdates(mClient, request,
new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.d(TAG, "onLocationChanged: " + location.getLatitude() + ", " +
location.getLongitude());
new SearchTask().execute(location);
}
});
} catch (SecurityException e) {
if (DEBUG) {
Log.e(TAG, "no permission", e);
}
}
}
示例8: createLocationRequest
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
private void createLocationRequest() {
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setFastestInterval(GPS_FASTEST_INTERVAL)
.setInterval(GPS_INTERVAL)
.setSmallestDisplacement(100f);
}
示例9: registerForLocationUpdates
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
@DebugLog
@SuppressLint("MissingPermission")
void registerForLocationUpdates() {
FusedLocationProviderClient locationProviderClient = getFusedLocationProviderClient();
LocationRequest locationRequest = LocationRequest.create();
Looper looper = Looper.myLooper();
locationProviderClient.requestLocationUpdates(locationRequest, locationCallback, looper);
}
示例10: onConnected
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
locationRequest=LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(30*1000);
locationRequest.setFastestInterval(5*1000);
LocationSettingsRequest.Builder builder=new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
locationSettingsResultPendingResult=LocationServices.SettingsApi
.checkLocationSettings(mGoogleApiClient,builder.build());
locationSettingsResultPendingResult.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
final Status status=locationSettingsResult.getStatus();
final LocationSettingsStates states=locationSettingsResult.getLocationSettingsStates();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
//All location settings are satisfied. The client can initialize location requests here
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
//Location settings are not satisfied but could be fixed by showing user a dialog
try {
status.startResolutionForResult(Gps4Activity.this,REQUEST_LOCATION);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
//Location settings are not satisfied and we have no way to fix the settings
//so we cannot show the dialog
break;
}
}
});
}
示例11: createListener
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
private void createListener() {
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(1000); // Update location every second
listenerReady = true;
if (startListener) {
startListener();
}
}
示例12: findImage
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
private void findImage() {
LocationRequest request = LocationRequest.create();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setNumUpdates(1);
request.setInterval(0);
LocationServices.FusedLocationApi
.requestLocationUpdates(mClient, request, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.i(TAG, "Got a fix: " + location);
new SearchTask().execute(location);
}
});
}
示例13: findCoords
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
private void findCoords() {
LocationRequest request = LocationRequest.create();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setNumUpdates(1);
request.setInterval(0);
LocationServices.FusedLocationApi
.requestLocationUpdates(mClient, request, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
double lat = location.getLatitude();
double lon = location.getLongitude();
mLocation.setLatitude(lat);
mLocation.setLongitude(lon);
mWasLocationFixed = true;
//Sort the order in which places are shown
//depending on how far they are from us (= by distance ascending)
Collections.sort(mPlaces, new Comparator<Visitable>() {
@Override
public int compare(Visitable a, Visitable b) {
Location aLoc = a.getLocation();
Location bLoc = b.getLocation();
return (int) aLoc.distanceTo(mLocation) - (int) bLoc.distanceTo(mLocation);
}
});
mAdapter.setPlaces(mPlaces);
mAdapter.notifyDataSetChanged();
}
});
}
示例14: enableLocation
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
@Override
public void enableLocation() {
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.build();
googleApiClient.connect();
LocationRequest locationRequestHighAccuracy = LocationRequest.create();
locationRequestHighAccuracy.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationRequest locationRequestBalancedPowerAccuracy = LocationRequest.create();
locationRequestBalancedPowerAccuracy.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequestHighAccuracy)
.addLocationRequest(locationRequestBalancedPowerAccuracy);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can initialize location
// requests here.
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
if (!isLocationSettingRequestDialogShowing) {
status.startResolutionForResult(MainActivity.this, LOCATION_REQUEST_CODE);
isLocationSettingRequestDialogShowing = true;
}
} catch (Exception ignored) {
isLocationSettingRequestDialogShowing = false;
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way to fix the
// settings so we won't show the dialog.
break;
}
}
});
}