Here are the examples of the java api class com.google.android.gms.location.LocationClient taken from open source projects.
1. MainActivity#addGeofences()
Project: AndroidWearable-Samples
File: MainActivity.java
File: MainActivity.java
/** * Start a request for geofence monitoring by calling LocationClient.connect(). */ public void addGeofences() { // Start a request to add geofences. mRequestType = REQUEST_TYPE.ADD; // Test for Google Play services after setting the request type. if (!isGooglePlayServicesAvailable()) { Log.e(TAG, "Unable to add geofences - Google Play services unavailable."); return; } // Create a new location client object. Since this activity class implements // ConnectionCallbacks and OnConnectionFailedListener, it can be used as the listener for // both parameters. mLocationClient = new LocationClient(this, this, this); // If a request is not already underway. if (!mInProgress) { // Indicate that a request is underway. mInProgress = true; // Request a connection from the client to Location Services. mLocationClient.connect(); // A request is already underway, so disconnect the client and retry the request. } else { mLocationClient.disconnect(); mLocationClient.connect(); } }
2. MainActivity#onCreate()
Project: AndroidDemoProjects
File: MainActivity.java
File: MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); verifyPlayServices(); mLocationClient = new LocationClient(this, this, this); mIntent = new Intent(this, GeofencingService.class); mPendingIntent = PendingIntent.getService(this, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT); mToggleButton = (ToggleButton) findViewById(R.id.geofencing_button); mToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b) { startGeofence(); } else { stopGeofence(); } } }); }
3. LocationGetLocationActivity#onCreate()
Project: coursera-android
File: LocationGetLocationActivity.java
File: LocationGetLocationActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!servicesAvailable()) finish(); setContentView(R.layout.main); mAccuracyView = (TextView) findViewById(R.id.accuracy_view); mTimeView = (TextView) findViewById(R.id.time_view); mLatView = (TextView) findViewById(R.id.lat_view); mLngView = (TextView) findViewById(R.id.lng_view); // Create new Location Client. This class will handle callbacks mLocationClient = new LocationClient(this, this, this); // Create and define the LocationRequest mLocationRequest = LocationRequest.create(); // Use high accuracy mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Update every 10 seconds mLocationRequest.setInterval(POLLING_FREQ); // Recieve updates no more often than every 2 seconds mLocationRequest.setFastestInterval(FASTES_UPDATE_FREQ); }
4. PTRMapFragment#onCreate()
Project: AndroidDemoProjects
File: PTRMapFragment.java
File: PTRMapFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLocationClient = new LocationClient(getActivity(), this, this); }