當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。