当前位置: 首页>>代码示例>>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;未经允许,请勿转载。