本文整理汇总了Java中com.google.android.gms.location.LocationClient.connect方法的典型用法代码示例。如果您正苦于以下问题:Java LocationClient.connect方法的具体用法?Java LocationClient.connect怎么用?Java LocationClient.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.location.LocationClient
的用法示例。
在下文中一共展示了LocationClient.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MyTracksLocationManager
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
public MyTracksLocationManager(Context context, Looper looper, boolean enableLocaitonClient) {
this.context = context;
this.handler = new Handler(looper);
if (enableLocaitonClient) {
locationClient = new LocationClient(context, connectionCallbacks, onConnectionFailedListener);
locationClient.connect();
} else {
locationClient = null;
}
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
contentResolver = context.getContentResolver();
observer = new GoogleSettingsObserver(handler);
isAllowed = GoogleLocationUtils.isAllowed(context);
contentResolver.registerContentObserver(
GoogleLocationUtils.USE_LOCATION_FOR_SERVICES_URI, false, observer);
}
示例2: applicationStartup
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
* @param savedInstanceState
*/
private void applicationStartup() {
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
mClient = new LocationClient(this, this, this);
mClient.connect();
} else {
EasyTracker.getInstance(this).send(MapBuilder
.createEvent(Category.Other.name(), "GooglePlayServicesNotAvailable", "", null)
.build());
}
mCities = mGetLatestCamerasTask.getCities();
mCacheParams = new ImageCacheParams("/image-cache");
setImageQuality();
configureAnalytics();
mImageWorker = new ImageFetcher(this, 400);
mImageWorker.setImageCache(ImageCache.findOrCreateCache(this,
mCacheParams));
mImageWorker.setLoadingImage(R.drawable.placeholder_camera);
mFragment.setIsProcessing(false);
mDrawerAdapter = new DrawerListAdapter(this,
Arrays.asList((getResources().getStringArray(R.array.drawer_list_groups))),
mCities);
mDrawerList.setAdapter(mDrawerAdapter);
selectGroup(mDrawerList, getCurrentGroup(), true);
}
示例3: setMockLocation
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
public void setMockLocation(final LatLng location) throws InterruptedException {
client = new LocationClient(this, new GooglePlayServicesClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
client.setMockMode(true);
Location newLocation = new Location("flp");
newLocation.setLatitude(location.latitude);
newLocation.setLongitude(location.longitude);
newLocation.setAccuracy(3f);
client.setMockLocation(newLocation);
}
@Override
public void onDisconnected() {
}
}, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Toast.makeText(MainActivity.this, "Make sure that Mock Location is enabled in developer settings", Toast.LENGTH_SHORT).show();
}
});
client.connect();
}
示例4: addGeofences
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
* 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();
}
}
示例5: onCreateView
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_camping, container,
false);
mLocationClient = new LocationClient(getActivity(), this, this);
// Create the LocationRequest object
mLocationRequest = LocationRequest.create();
// Use high accuracy
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the update interval to 5 seconds
mLocationRequest.setInterval(UPDATE_INTERVAL);
// Set the fastest update interval to 1 second
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationClient.connect();
return rootView;
}
示例6: onCreateView
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
mLocationClient = new LocationClient(getActivity(), this, this);
// Create the LocationRequest object
mLocationRequest = LocationRequest.create();
// Use high accuracy
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the update interval to 5 seconds
mLocationRequest.setInterval(UPDATE_INTERVAL);
// Set the fastest update interval to 1 second
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationClient.connect();
setHasOptionsMenu(true);
return rootView;
}
示例7: onCreate
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
public void onCreate() {
Log.d(TAG, "onCreate()");
super.onCreate();
if (!servicesAvailable()) {
stopSelf();
return;
}
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
.setInterval(15 * 60 * 1000)
.setFastestInterval(1 * 60 * 1000);
mLocationClient = new LocationClient(this, this, this);
mLocationClient.connect();
}
示例8: getCurrentLocation
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@SuppressLint("HandlerLeak")
private void getCurrentLocation() {
if (isLocationServiceEnabled) {
handleLocationRequestTimeout();
int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
Log.d(SmartConstants.APP_NAME, "LocationService->play services:" + resp);
if (resp == ConnectionResult.SUCCESS) {
locationclient = new LocationClient(context, this, this);
locationclient.connect();
showProgressDialog();
final LocationListener locListener = this;
Handler locationHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
locationrequest = LocationRequest.create();
locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationrequest.setInterval(TIME_INTERVAL_BW_REQUESTS);
locationrequest.setNumUpdates(1);
locationclient.requestLocationUpdates(locationrequest, locListener);
}
};
locationHandler.sendEmptyMessageDelayed(0, 1000);
} else {
onErrorLocationOperation(ExceptionTypes.LOCATION_ERROR_PLAY_SERVICE_NOT_AVAILABLE, ExceptionTypes.LOCATION_ERROR_PLAY_SERVICE_NOT_AVAILABLE_MESSAGE);
}
} else {
// Means that the location service of the device is not turned on
// Prompt the user to turn on the Location service
showDecisionDialog("Location Service Disabled", "Location service is disabled in your device. Enable it?", "Enable Location", "No");
}
}
示例9: onCreate
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
queueSend = false;
prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
if(servicesConnected()){
locationClient = new LocationClient(this, this, this);
locationClient.connect();
}
}
示例10: onCreate
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
public void onCreate() {
super.onCreate();
geoService = this;
int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resp == ConnectionResult.SUCCESS) {
locationclient = new LocationClient(this, connectionListener, this);
locationclient.connect();
} else {
Toast.makeText(this, "Google Play Service Error " + resp,
Toast.LENGTH_LONG).show();
}
}
示例11: onReceive
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, final Intent intent)
{
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final LocationClient locationClient = new LocationClient(context, connectionCallbacks, onConnectionFailedListener);
locationClient.registerConnectionCallbacks(new ConnectionCallbacks() {
@Override
public void onDisconnected()
{
Log.d(LOG, "StopTracking.onDisconnected");
}
@Override
public void onConnected(Bundle arg0)
{
final PendingIntent service = PendingIntent.getService(context, 0,
new Intent(context, ShareByTracking.class), PendingIntent.FLAG_UPDATE_CURRENT);
locationClient.removeLocationUpdates(service);
locationClient.disconnect();
notificationManager.cancel(R.string.app_name);
Log.d(LOG, "StopTracking.onConnected");
}
});
locationClient.connect();
}
示例12: getWeatherFromPlayServices
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
* Called when the user has their location set to automatic.
* This will connect to google play services to get the last location
* from their device.
*/
private void getWeatherFromPlayServices() {
mPlayServicesLocationClient = new LocationClient(getContext(), new GooglePlayServicesClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
// client has connected, so lets get the location
final Location lastLocation = mPlayServicesLocationClient.getLastLocation();
// disconnect the client to end networking
mPlayServicesLocationClient.disconnect();
mPlayServicesLocationClient = null;
// set the weather data from that location
new Thread(new Runnable() {
@Override
public void run() {
setWeaterDataFromGeo(lastLocation);
}
}).start();
}
@Override
public void onDisconnected() {
// client has disconnected
mPlayServicesLocationClient = null;
}
}, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
// something went wrong, may expand here later
mPlayServicesLocationClient = null;
}
});
// get the connection
mPlayServicesLocationClient.connect();
}
示例13: onStartCommand
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (isServiceRunning()) {
// Do not call super i.e. do not call onHandleIntent
return IntentService.START_NOT_STICKY;
}
singletonLocationService = this;
Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
Toast.makeText(this, R.string.noGooglePlayServices,
Toast.LENGTH_LONG).show();
// Do not call super i.e. do not call onHandleIntent
return IntentService.START_NOT_STICKY;
}
locationClient = new LocationClient(this, this, this);
locationClient.connect();
if (!openOutputFile()) {
// Do not call super i.e. do not call onHandleIntent
return IntentService.START_NOT_STICKY;
}
JourneyPreferences.registerOnSharedPreferenceChangeListener(this, this);
setForegroundNotification();
return super.onStartCommand(intent, flags, startId);
}
示例14: FusedPositionManager
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
public FusedPositionManager(Context context, final GPSCConnectionHandler gPSCConnectionHandler) {
intentService = new Intent(context, FusedLocationService.class);
pendingIntent = PendingIntent.getService(context, 1, intentService, 0);
int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if (resp == ConnectionResult.SUCCESS) {
locationclient = new LocationClient(context, new GooglePlayServicesClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
gPSCConnectionHandler.onConnected(bundle);
}
@Override
public void onDisconnected() {
gPSCConnectionHandler.onDisconnected();
}
}, new GooglePlayServicesClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
gPSCConnectionHandler.onConnectionFailed(connectionResult);
}
}
);
locationclient.connect();
} else {
Log.e("error","googleplayservices is not available");
}
}
示例15: onCreate
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
@Override public void onCreate() {
super.onCreate();
RUNNING = true;
BusProvider.getInstance().register(this);
mLocationClient = new LocationClient(this, this, this);
mLocationClient.connect();
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(Constants.UPDATE_INTERVAL);
mLocationRequest.setFastestInterval(Constants.FASTEST_INTERVAL);
mProgressBar = new ProgressBar(getBaseContext(), null,
android.R.attr.progressBarStyleHorizontal);
mProgressBar.getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.x = 0;
params.y = 0;
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.addView(mProgressBar, params);
showRunningNotification("Initialising " + getString(R.string.app_name));
}