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


Java LocationListener類代碼示例

本文整理匯總了Java中com.google.android.gms.location.LocationListener的典型用法代碼示例。如果您正苦於以下問題:Java LocationListener類的具體用法?Java LocationListener怎麽用?Java LocationListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocationListener類屬於com.google.android.gms.location包,在下文中一共展示了LocationListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startLocationMoitoring

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
private void startLocationMoitoring() {
	if (googleApiClient.isConnected()) {
		LocationRequest locationRequest = LocationRequest.create()
			.setInterval(10000)
			.setFastestInterval(5000)
			.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) {
			return;
		}
		LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, new LocationListener() {
			@Override
			public void onLocationChanged(Location location) {
				Log.d(TAG, "location update");
				currentLocation = location;
			}
		});
	}
}
 
開發者ID:team-htbr,項目名稱:1617PROJ1Bloeddonatie-app,代碼行數:20,代碼來源:MainActivity.java

示例2: requestLocation

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
/**
 * Tests for requestLocation.
 *
 * @throws Exception
 */
@Test
public void requestLocation() throws Exception {
  GoogleApiClient mockGoogleApiClient = mock(GoogleApiClient.class);
  doReturn(true).when(mockGoogleApiClient).isConnected();

  LocationManager mockLocationManager = spy(mLocationManager);
  Whitebox.setInternalState(mockLocationManager, "googleApiClient", mockGoogleApiClient);

  FusedLocationProviderApi mockLocationProviderApi = mock(FusedLocationProviderApi.class);
  Whitebox.setInternalState(LocationServices.class, "FusedLocationApi", mockLocationProviderApi);

  // Testing when a customer did not disableLocationCollection.
  Whitebox.invokeMethod(mockLocationManager, "requestLocation");
  verify(mockLocationProviderApi).requestLocationUpdates(any(GoogleApiClient.class),
      any(LocationRequest.class), any(LocationListener.class));

  // Testing when a customer disableLocationCollection.
  Leanplum.disableLocationCollection();
  Whitebox.invokeMethod(mockLocationManager, "requestLocation");
  verifyNoMoreInteractions(mockLocationProviderApi);
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:27,代碼來源:LeanplumLocationManagerTest.java

示例3: findImage

import com.google.android.gms.location.LocationListener; //導入依賴的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

示例4: startLocationUpdate

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
private void startLocationUpdate(
    GoogleApiClient googleApiClient,
    LocationListener locationListener
) {
  boolean a = ActivityCompat.checkSelfPermission(getApplicationContext(),
      Manifest.permission.ACCESS_FINE_LOCATION
  ) != PackageManager.PERMISSION_GRANTED;
  boolean b = ActivityCompat.checkSelfPermission(getApplicationContext(),
      Manifest.permission.ACCESS_COARSE_LOCATION
  ) != PackageManager.PERMISSION_GRANTED;
  if (a && b) {
    googleApiClient.disconnect();
    return;
  }
  LocationServices.FusedLocationApi.requestLocationUpdates(
      googleApiClient,
      new LocationRequest().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY),
      locationListener);
}
 
開發者ID:drfonfon,項目名稱:ITagAntiLost,代碼行數:20,代碼來源:LocationChangeService.java

示例5: onConnected

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
@Override
public void onConnected(Bundle bundle) {
    initializeLocationRequest(10, 1000);
    LocationServices.FusedLocationApi.requestLocationUpdates(mClient, mLocationRequest, new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            currentLocation = location;
            mapUtil.moveMap(mMap, currentLocation, 15);
        }
    });

    currentLocation = LocationServices.FusedLocationApi.getLastLocation(mClient);
    if (currentLocation != null) {
        mapUtil.moveMap(mMap, currentLocation, 15);
    }
}
 
開發者ID:CMPUT301F16T02,項目名稱:Dryver,代碼行數:17,代碼來源:ActivityRequestMap.java

示例6: startLocationManagerAfterLogin

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
private void startLocationManagerAfterLogin() {
    mProgressFacebook.setVisibility(View.VISIBLE);

    mFacebookLoginButton.setVisibility(View.INVISIBLE);
    mTwitterLoginButton.setVisibility(View.INVISIBLE);
    mInstaLoginButton.setVisibility(View.INVISIBLE);

    mLocationManager.startLocationUpdates(new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                handleLocationUpdate(location);
            }
        }
    });
}
 
開發者ID:Popdeem,項目名稱:Popdeem-SDK-Android,代碼行數:17,代碼來源:PDUISocialMultiLoginFragment.java

示例7: onConnected

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
@Override
public void onConnected(@Nullable Bundle bundle) {
    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(2000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequest);
    LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
            builder.build());
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {

        }
    });
}
 
開發者ID:snigle,項目名稱:corsaire,代碼行數:21,代碼來源:MyAddressService.java

示例8: onConnected

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
@SuppressWarnings("MissingPermission")
@Override
public void onConnected(@Nullable Bundle bundle) {
    if (PermissionUtils.isLocationPermissionGranted(this)) {
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, mLocationRequest, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                currLocation = new LatLng(location.getLatitude(), location.getLongitude());
                // Creating a LatLng object for the current location
            }
        });

        Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        if (lastLocation != null) {
            currLocation = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
        } else
            Toast.makeText(StoreDetailActivity.this, "Cannot get current location!", Toast.LENGTH_SHORT).show();
    } else {
        PermissionUtils.requestLocaiton(this);
    }
}
 
開發者ID:HCMUS-AssignmentWarehouse,項目名稱:FastFoodFinder,代碼行數:22,代碼來源:StoreDetailActivity.java

示例9: startLocationListening

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
public void startLocationListening(Context context, LocationListener locationListener) {
    this.context = context;
    this.locationListener = locationListener;
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(context)
                .addConnectionCallbacks(this)
                .addApi(LocationServices.API)
                .build();

    }
    mGoogleApiClient.connect();

    mLocationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(MIN_UPDATE_INTERVAL_IN_SECONDS * 1000);
}
 
開發者ID:Project-Helin,項目名稱:drone-onboard-app,代碼行數:17,代碼來源:LocationService.java

示例10: checkLocationAndInit

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
private void checkLocationAndInit() {
  if (sLastLocation == null) {
    sLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
  }

  if (sLastLocation == null) {
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, createLocationRequest(), new LocationListener() {
      @Override
      public void onLocationChanged(Location location) {
        sLastLocation = location;
        if (mCallback != null) {
          mCallback.onLocationChanged(sLastLocation);
        }
        initAppAfterCheckingLocation();
        LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
      }
    });

  } else {
    initAppAfterCheckingLocation();
  }
}
 
開發者ID:alphamu,項目名稱:PrayTime-Android,代碼行數:23,代碼來源:LocationHelper.java

示例11: locationSettingSuccess

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
@SuppressLint("MissingPermission")
@Override
protected void locationSettingSuccess(final ResourceObserver<Location> emitter, GoogleApiClient client) {
    this.client = client;
    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            emitter.onNext(location);
            if (locationRequest.getNumUpdates() == 1) {
                emitter.onComplete();
            }
        }
    };

    //noinspection MissingPermission
    LocationServices.FusedLocationApi.requestLocationUpdates(client, locationRequest, locationListener);
}
 
開發者ID:finn-no,項目名稱:rxactivityresponse,代碼行數:18,代碼來源:LocationObservable.java

示例12: requestLocationUpdates

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
@Override
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
public Observable<Location> requestLocationUpdates(LocationRequest request) {
    return Observable.create(emitter -> {
        GoogleApiClient client = mBuilder.build();
        LocationListener listener = emitter::onNext;
        GoogleApiClients.connect(client, hint -> FusedLocationApi
                .requestLocationUpdates(client, request, listener, Loopers.nullOrMain())
                .setResultCallback(status -> {
                    if (!status.isSuccess()) {
                        emitter.onComplete();
                    }
                }), result -> emitter.onComplete());
        emitter.setCancellable(() -> {
            if (client.isConnected()) {
                FusedLocationApi.removeLocationUpdates(client, listener);
            }
            client.disconnect();
        });
    });
}
 
開發者ID:pushbit,項目名稱:sprockets-android,代碼行數:22,代碼來源:GoogleLocationProvider.java

示例13: requestLocationUpdates

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
public void requestLocationUpdates(LocationRequest request, final LocationListener listener)
        throws RemoteException {
    if (nativeLocation != null) {
        nativeLocation.requestLocationUpdates(request, listener);
    } else {
        if (!listenerMap.containsKey(listener)) {
            listenerMap.put(listener, new ILocationListener.Stub() {
                @Override
                public void onLocationChanged(Location location) throws RemoteException {
                    listener.onLocationChanged(location);
                }
            });
        }
        getServiceInterface().requestLocationUpdatesWithPackage(request,
                listenerMap.get(listener), getContext().getPackageName());
    }
}
 
開發者ID:microg,項目名稱:android_external_GmsLib,代碼行數:18,代碼來源:LocationClientImpl.java

示例14: requestLocationUpdates

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
public void requestLocationUpdates(LocationRequest paramLocationRequest, LocationListener paramLocationListener, Looper paramLooper)
{
  this.xP.bP();
  if (paramLooper == null)
    eg.b(Looper.myLooper(), "Can't create handler inside thread that has not called Looper.prepare()");
  synchronized (this.xS)
  {
    b localb1 = (b)this.xS.get(paramLocationListener);
    b localb2 = localb1;
    if (localb1 == null)
      localb2 = new b(paramLocationListener, paramLooper);
    this.xS.put(paramLocationListener, localb2);
    try
    {
      ((gl)this.xP.bQ()).a(paramLocationRequest, localb2, this.mContext.getPackageName());
    }
    catch (RemoteException localRemoteException)
    {
      throw new IllegalStateException(localRemoteException);
    }
    return;
  }
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:24,代碼來源:gm.java

示例15: onGoogleApiClientReady

import com.google.android.gms.location.LocationListener; //導入依賴的package包/類
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Location> observer) {
    listener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            observer.onNext(location);
        }
    };
    LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, listener);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:LocationUpdatesObservable.java


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