diff options
| author | 2013-06-06 17:49:27 +0000 | |
|---|---|---|
| committer | 2013-06-06 17:49:27 +0000 | |
| commit | a2425f6825a88fb04f3a22e018311bf2e2a5ac4e (patch) | |
| tree | e0cf714ed5753b3bda18b9d1a7b134f3b08fa8ee | |
| parent | 758cedd116f1c6ea4b8b936a76cd77d592868209 (diff) | |
| parent | 5b4438ebb3fe62ef0d034f0ab5b241b9cb76cd83 (diff) | |
Merge "Doc bug B9297954: Fixes to Location APIs" into jb-mr2-dev
| -rw-r--r-- | docs/html/training/location/receive-location-updates.jd | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/docs/html/training/location/receive-location-updates.jd b/docs/html/training/location/receive-location-updates.jd index c33f07547d24..e6e8c51a5078 100644 --- a/docs/html/training/location/receive-location-updates.jd +++ b/docs/html/training/location/receive-location-updates.jd @@ -417,7 +417,7 @@ public class MainActivity extends FragmentActivity implements public static final int UPDATE_INTERVAL_IN_SECONDS = 5; // Update frequency in milliseconds private static final long UPDATE_INTERVAL = - MILLISECONDS_PER_SECOND * UPDATE_INTERVAL_IN SECONDS; + MILLISECONDS_PER_SECOND * UPDATE_INTERVAL_IN_SECONDS; // The fastest update frequency, in seconds private static final int FASTEST_INTERVAL_IN_SECONDS = 1; // A fast frequency ceiling in milliseconds @@ -425,7 +425,7 @@ public class MainActivity extends FragmentActivity implements MILLISECONDS_PER_SECOND * FASTEST_INTERVAL_IN_SECONDS; ... // Define an object that holds accuracy and frequency parameters - LocationResult mLocationRequest; + LocationRequest mLocationRequest; ... @Override protected void onCreate(Bundle savedInstanceState) { @@ -458,9 +458,11 @@ public class MainActivity extends FragmentActivity implements the request by calling <code><a href="{@docRoot}reference/com/google/android/gms/location/LocationClient.html#requestLocationUpdates(com.google.android.gms.location.LocationRequest, com.google.android.gms.location.LocationListener)">requestLocationUpdates()</a></code>. Since your client must be connected for your app to receive updates, you should - connect the client and make the request in + connect the client in {@link android.support.v4.app.FragmentActivity#onStart onStart()}. This ensures that you always - have a valid, connected client while your app is visible. + have a valid, connected client while your app is visible. Since you need a connection before you + can request updates, make the update request in +<code><a href="{@docRoot}reference/com/google/android/gms/common/GooglePlayServicesClient.ConnectionCallbacks.html#onConnected(android.os.Bundle)">ConnectionCallbacks.onConnected()</a></code> </p> <p> Remember that the user may want to turn off location updates for various reasons. You should @@ -536,6 +538,21 @@ public class MainActivity extends FragmentActivity implements } } ... + /* + * Called by Location Services when the request to connect the + * client finishes successfully. At this point, you can + * request the current location or start periodic updates + */ + @Override + public void onConnected(Bundle dataBundle) { + // Display the connection status + Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show(); + // If already requested, start periodic updates + if (mUpdatesRequested) { + mLocationClient.requestLocationUpdates(mLocationRequest, this); + } + } + ... } </pre> <p> |