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


Java LocationRequest類代碼示例

本文整理匯總了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!");
}
 
開發者ID:armendu,項目名稱:traffic-report-android,代碼行數:17,代碼來源:MainActivity.java

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

示例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);
        }
    }
 
開發者ID:jpmeijers,項目名稱:ttnmapper_android_v2,代碼行數:17,代碼來源:TTNMapperService.java

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

示例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);
    });
}
 
開發者ID:niqo01,項目名稱:RxTask,代碼行數:19,代碼來源:RxFusedLocationProviderClient.java

示例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));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:MockLocationsActivity.java

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

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

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

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

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

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

    }
 
開發者ID:webianks,項目名稱:Crimson,代碼行數:18,代碼來源:SearchClinics.java

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

示例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);
}
 
開發者ID:CMPUT301W17T08,項目名稱:Moodr,代碼行數:24,代碼來源:MapsActivity.java

示例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;
    }
}
 
開發者ID:MustansirZia,項目名稱:react-native-fused-location,代碼行數:18,代碼來源:FusedLocationModule.java

示例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);
}
 
開發者ID:if710,項目名稱:2017.2-codigo,代碼行數:24,代碼來源:FusedLocationMapActivity.java


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