
Android Wear Docs, Release 1.1
// Register listener using the LocationRequest object
LocationServices.FusedLocationApi.requestLocationUpdates(googleClient, locationRequest, this);
}
// Disconnect from Google Play Services when the Activity stops
@Override
protected void onStop() {
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
googleClient.disconnect();
}
super.onStop();
}
// Placeholders for required connection callbacks
@Override
public void onConnectionSuspended(int cause) { }
@Override
public void onConnectionFailed(ConnectionResult connectionResult) { }
3. Implement the LocationListener callback for location updates.
@Override
public void onLocationChanged(Location location){
// Display the latitude and longitude in the UI
mTextView.setText("Latitude: " + String.valueOf( location.getLatitude()) +
"\nLongitude: " + String.valueOf( location.getLongitude()));
}
This example displays the current latitude and longitude in the wearable UI. The location is from the handheld GPS.
When the wearable is not paired with the handheld, for example when you leave the wearable behind to exercise, the
GPS automatically switches to the onboard GPS.
This screen capture is from the Sony SmartWatch 3. The number of digits displayed is greater now, providing a visual
clue that the wearable GPS is active. When you return and re-pair with the handheld, the GPS automatically switches
back to the handheld and the display returns to its original format.
8.1. First Wearable GPS 39
Comentarios a estos manuales