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