使用谷歌播放服務,您需要成立了谷歌API客戶端第一
private void setUpApi() {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
當客戶端連接,你可以設置你的提醒,使用您已經知道座標:
@Override
public void onConnected(Bundle connectionHint) {
Log.d(TAG, "connected!!");
Geofence cinemaFence = new Geofence.Builder()
.setRequestId(id) // some id for you
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
.setCircularRegion(mLatitude, mLongtitude, mRadius)
.build();
GeofencingRequest request = new GeofencingRequest.Builder()
.addGeofence(cinemaFence)
.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
.build();
// Now we create an intent that will be fired when the user enters the region
Intent intent = new Intent(mContext, UserTransitionIntentService.class);
intent.putExtra(UserTransitionIntentService.EXTRA_FEATURES, getFeaturesFlag());
PendingIntent pi = PendingIntent.getService(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, request, pi);
}
整個項目可以在這裏找到:https://github.com/alexstyl/Location-Reminder
邁克你好,你有什麼解決方法嗎? –