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