本文整理汇总了Java中com.google.android.gms.location.LocationClient.requestLocationUpdates方法的典型用法代码示例。如果您正苦于以下问题:Java LocationClient.requestLocationUpdates方法的具体用法?Java LocationClient.requestLocationUpdates怎么用?Java LocationClient.requestLocationUpdates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.location.LocationClient
的用法示例。
在下文中一共展示了LocationClient.requestLocationUpdates方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
示例2: LocationTracking
import com.google.android.gms.location.LocationClient; //导入方法依赖的package包/类
/**
* Subscribes for location updates
*
* The updates will be received with the interval INTERVAL_UPDATE (ms)
* @param context current context
* @param locationListener Callback
*/
public LocationTracking(final Context context, final LocationListener locationListener) {
locationclient = new LocationClient(context, new GooglePlayServicesClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
Toast.makeText(context, "Connected to GPS!!", Toast.LENGTH_LONG)
.show();
locationclient.requestLocationUpdates(
LocationRequest.create().setInterval(INTERVAL_UPDATE)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY),
locationListener);
}
@Override
public void onDisconnected() {
Toast.makeText(context, "Disconnected from GPS!!", Toast.LENGTH_LONG)
.show();
}
}, new GooglePlayServicesClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Toast.makeText(context, "Failed to connect to GPS!!", Toast.LENGTH_LONG)
.show();
}
}
);
locationclient.connect();
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Toast.makeText(context,
"Please enable gps to get a more accurate location tracking", Toast.LENGTH_LONG)
.show();
Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}