當前位置: 首頁>>代碼示例>>Java>>正文


Java LocationRequest.create方法代碼示例

本文整理匯總了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));
}
 
開發者ID:philiWeitz,項目名稱:react-native-location-switch,代碼行數:19,代碼來源:LocationSwitch.java

示例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);
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-android,代碼行數:18,代碼來源:LocationClient.java

示例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);

}
 
開發者ID:OldBigBuddha,項目名稱:AlarmWithL-T,代碼行數:22,代碼來源:SettingFragment.java

示例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);
  }
}
 
開發者ID:mapbox,項目名稱:mapbox-events-android,代碼行數:22,代碼來源:GoogleLocationEngine.java

示例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();

}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:18,代碼來源:GpsShield.java

示例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));
    }
}
 
開發者ID:PalisadoesFoundation,項目名稱:do-road,代碼行數:27,代碼來源:MainActivity.java

示例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);
        }
    }
}
 
開發者ID:ivicel,項目名稱:Android-Programming-BigNerd,代碼行數:22,代碼來源:LocatrFragment.java

示例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);

}
 
開發者ID:cahergil,項目名稱:Farmacias,代碼行數:9,代碼來源:GPSTrackerFragment.java

示例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);
}
 
開發者ID:StylingAndroid,項目名稱:LocationServices,代碼行數:9,代碼來源:LocationFragment.java

示例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;
            }
        }
    });
}
 
開發者ID:Pritom14,項目名稱:Gps,代碼行數:40,代碼來源:Gps4Activity.java

示例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();
    }
}
 
開發者ID:PacktPublishing,項目名稱:Expert-Android-Programming,代碼行數:12,代碼來源:SelectLocationActivity.java

示例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);
                }
            });
}
 
開發者ID:rsippl,項目名稱:AndroidProgramming3e,代碼行數:15,代碼來源:LocatrFragment.java

示例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();
                }
            });
}
 
開發者ID:plweegie,項目名稱:piast-trail,代碼行數:32,代碼來源:PlaceListFragment.java

示例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;
            }
        }
    });
}
 
開發者ID:GrenderG,項目名稱:Protestr,代碼行數:46,代碼來源:MainActivity.java


注:本文中的com.google.android.gms.location.LocationRequest.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。