本文整理汇总了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;
}
});
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
});
}
示例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) {
}
});
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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);
}
示例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();
});
});
}
示例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());
}
}
示例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;
}
}
示例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);
}