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