当前位置: 首页>>代码示例>>Java>>正文


Java LocationServices类代码示例

本文整理汇总了Java中com.google.android.gms.location.LocationServices的典型用法代码示例。如果您正苦于以下问题:Java LocationServices类的具体用法?Java LocationServices怎么用?Java LocationServices使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LocationServices类属于com.google.android.gms.location包,在下文中一共展示了LocationServices类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLocation

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
private void getLocation() {
    /*if (ActivityCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MapsActivity.this, 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;
    }*/
    checkLocationPermission();
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    if (mCircleSnap && mLastLocation != null) {
        LatLng latLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(16));
    }
}
 
开发者ID:kav0rka,项目名称:VennTracker,代码行数:20,代码来源:MapsActivity.java

示例2: checkLocationSettings

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
/**
 * Check whether gps is turned on or not.
 */
public boolean checkLocationSettings() {
    // In case of a test session don't check settings
    if (((AppRunnest) activity.getApplication()).isTestSession()) {
        return true;
    }

    if (!gpsIsTurnedOn) {
        PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(
                googleApiClient,
                locationSettingsRequest);
        result.setResultCallback(this);
    }

    return gpsIsTurnedOn;
}
 
开发者ID:IrrilevantHappyLlamas,项目名称:Runnest,代码行数:19,代码来源:LocationSettingsHandler.java

示例3: onConnected

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
    //Compruebo los permisos de la localización
    //si no los tengo me salgo del método
    if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
            ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        //Pongo mi localización en el mapa
        mMap.setMyLocationEnabled(true);
    }else
        ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);

    //Obtengo la última localización conocida
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
    if (mLastLocation != null) {
        miPosicion = new LatLng(mLastLocation.getLatitude(),mLastLocation.getLongitude());
        if(mMap!=null)
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(miPosicion,12));
    }
}
 
开发者ID:nen155,项目名称:TFG-SmartU-La-red-social,代码行数:21,代码来源:FragmentMapa.java

示例4: onCreate

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBundle = savedInstanceState;
    if (getArguments() != null) {
        proyecto = getArguments().getParcelable(ARG_PROYECTO);
    }
    //Para localizar al usuario inicializo la variable de la API de Google Maps
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(getContext())
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
    }
}
 
开发者ID:nen155,项目名称:TFG-SmartU-La-red-social,代码行数:17,代码来源:FragmentMapaProyecto.java

示例5: onConnected

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
    //Compruebo los permisos de la localización
    //si no los tengo me salgo del método
    if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
            ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        //Pongo mi localización en el mapa
        mMap.setMyLocationEnabled(true);
    }else
        ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
    //Obtengo la última localización conocida
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
    if (mLastLocation != null) {
        miPosicion = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
        if (mMap != null)
            if (posicionProyecto != null)
                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(posicionProyecto, 12));
            else
                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(miPosicion, 12));
    }
}
 
开发者ID:nen155,项目名称:TFG-SmartU-La-red-social,代码行数:23,代码来源:FragmentMapaProyecto.java

示例6: registerAllGeofences

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
/**
 * Registers the list of geofences specified in mGeofenceList with Google Play Services
 * Uses {@code #mClient } to connect to google play services
 * Uses {@link #getGeofenceRequest()} to get the list of Geofences to be registered
 * Uses {@link #getGeofencePendingIntent()} to get the pending intent to launch the intent service
 * when the geofence is triggered
 * Triggers {@link #onResult(Result)} when the geofences have been registered successfully
 */
public void registerAllGeofences() {
    if (mClient == null || !mClient.isConnected()
            || mGeofenceList == null || mGeofenceList.size() == 0) {
        return;
    }

    try {
        LocationServices.GeofencingApi.addGeofences(mClient,
                getGeofenceRequest(),
                getGeofencePendingIntent()).setResultCallback(this);
    }
    catch (SecurityException securityException){
        securityException.printStackTrace();
    }
}
 
开发者ID:samagra14,项目名称:Shush,代码行数:24,代码来源:Geofencing.java

示例7: onRequestPermissionsResult

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case REQUEST_ALL_PERMISSIONS: {
            for (int grantResult : grantResults) {
                if (grantResult != PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(this, R.string.persmissions_non_accordees, Toast.LENGTH_LONG);
                    return;
                }
            }

            finishIntialisation();
            initMap();
            // noinspection MissingPermission
            LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, createLocationRequest(), this);
            return;
        }
        // other 'case' lines to check for other
        // permissions this app might request
    }
}
 
开发者ID:ANFR-France,项目名称:proto-collecte,代码行数:22,代码来源:MainActivity.java

示例8: addGeofences

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
public static void addGeofences(final Context context, GoogleApiClient googleApiClient) {
    checkGoogleApiClient(googleApiClient);
    List<Place> places = new RemindyDAO(context).getActivePlaces();

    if(places.size() > 0) {
        if (PackageManager.PERMISSION_GRANTED == ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) {
            LocationServices.GeofencingApi.addGeofences(
                    googleApiClient,
                    getGeofencingRequest(places),
                    getGeofencePendingIntent(context)
            ).setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if(status.isSuccess())
                        Toast.makeText(context, "Geofences added/updated!", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

}
 
开发者ID:abicelis,项目名称:Remindy,代码行数:22,代码来源:GeofenceUtil.java

示例9: removeGeofences

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
/**
 * Removes geofences, which stops further notifications when the device enters or exits
 * previously registered geofences.
 */
public void removeGeofences() {
    if (!mGoogleApiClient.isConnected()) {
        Toast.makeText(context, context.getString(R.string.not_connected), Toast.LENGTH_SHORT).show();
        return;
    }
    try {
        // Remove geofences.
        LocationServices.GeofencingApi.removeGeofences(
                mGoogleApiClient,
                // This is the same pending intent that was used in addGeofences().
                getGeofencePendingIntent()
        ).setResultCallback(this); // Result processed in onResult().
    } catch (SecurityException securityException) {
        // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
        logSecurityException(securityException);
    }
}
 
开发者ID:RobinCaroff,项目名称:MyGeofencer,代码行数:22,代码来源:GeofencingController.java

示例10: startLocationUpdates

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
private void startLocationUpdates() {
        
     // set location interval updates
    initLocationRequest();
        
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Log.i(LOGSERVICE, "Permission not granted.");
        return;
    } else {
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
        buildGoogleApiClient();
        // enter current location in lat lng into firebase
        if (mUser.getUserID() != null) {
            mDatabase.child("users").child(mUser.getUserID()).child("latitude").setValue(userLocation.latitude);
            mDatabase.child("users").child(mUser.getUserID()).child("longitude").setValue(userLocation.longitude);
        } else {
            Toast.makeText(getApplicationContext(), "Current user not recognized. Try reauthenticating.",
                    Toast.LENGTH_LONG).show();
        }
    }
}
 
开发者ID:panzerama,项目名称:Dispatch,代码行数:22,代码来源:LocationUpdaterService.java

示例11: updateLocation

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
private void updateLocation() {
    Log.v(TAG, "Trying to update location...");
    if (isDelayedUpdate()) Log.v(TAG, "Detected delayed updates.");
    else {
        if (checkConnection()) {
            if (hasPermissions()) {
                setRequestingPermissions(true);
                LocationSettingsRequest.Builder builder =
                        new LocationSettingsRequest.Builder().addLocationRequest(
                                getLocationRequest()).setAlwaysShow(true);

                LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
                        builder.build()).setResultCallback(getLocationSettingsResultCallback());
                Log.v(TAG, "Settings verification requested.");
            } else checkForPermissions();
        }
    }
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:19,代码来源:LocationAdapter.java

示例12: startGps

import com.google.android.gms.location.LocationServices; //导入依赖的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

示例13: onConnected

import com.google.android.gms.location.LocationServices; //导入依赖的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: onCreate

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
@Override
public void onCreate() {
    Log.i(LOGSERVICE, "In onCreate");
    super.onCreate();
        
    // Build GoogleApiClient
    buildGoogleApiClient();
        
    // Firebase Authorization
    mAuth = FirebaseAuth.getInstance();
    mUserManager = new UserManager();
        
    // Set User event listener
    setUserEventListener();
    mUserManager.getUser(mAuth.getCurrentUser().getUid(), new IGetUserListener() {
        @Override
        public void onGetSingleUser(User retrievedUser) {
            mUser = retrievedUser;
        }
        @Override
        public void onFailedSingleUser() {
        }
    });
        
    mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
}
 
开发者ID:panzerama,项目名称:Dispatch,代码行数:27,代码来源:LocationUpdaterService.java

示例15: run

import com.google.android.gms.location.LocationServices; //导入依赖的package包/类
@Override
@SuppressWarnings({"MissingPermission"})
public void run() {
    Location loc=LocationServices.FusedLocationApi.getLastLocation(playServices);
    //se nao tem objeto valido, agenda pra tentar daqui a pouco
    /*
    if (loc == null) {
        getListView().postDelayed(this, 1000);
    }
    else {
        adapter.add(loc);
    }
    /**/

    //implementacao alternativa
    if (loc != null) {
        adapter.add(loc);
    }
    //getListView().postDelayed(this, 5000);
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:21,代码来源:FusedLocationActivity.java


注:本文中的com.google.android.gms.location.LocationServices类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。