小编gre*_*gor的帖子

地理围栏没有触发(待处理用户和广播接收者)

我已经使用了Geofences的Android教程,显然,当app关闭时,它不起作用.所以,在搜索了之后,我注意到SO上的用户b-ryce使用了BroadcastReceiver,因此即使应用程序不活动也会触发地理围栏(链接为他的SO问题).

当我移动到外部/内部注册位置时,我无法强制地理围栏触发.这是我的程序:

    /**
     * GeoLocation library
     */
    mGeoLocation = new GeoLocation(sInstance);


    /**
     * mReceiver init
     */
    mReceiver = new Receiver();
    sInstance.registerReceiver(mReceiver, mReceiver.createIntentFilter());
Run Code Online (Sandbox Code Playgroud)

在GeoLocation类中:

/*
 * Create a PendingIntent that triggers an IntentService in your
 * app when a geofence transition occurs.
 */
protected PendingIntent getTransitionPendingIntent() {
    if (mGeoPendingIntent != null) {
        return mGeoPendingIntent;
    }

    else {

        // Create an explicit Intent
        //  Intent intent = new Intent(mContext,
        //          ReceiveTransitionsIntentService.class);

        Intent intent = new Intent(getClass().getPackage().getName() + ".GEOFENCE_RECEIVE");

        /**
         * …
Run Code Online (Sandbox Code Playgroud)

android geolocation android-pendingintent android-geofence

6
推荐指数
1
解决办法
7232
查看次数

RxJS Observable返回数组,每次迭代运行另一个函数

我有一个函数getNews(),它基本上返回angular的http.get请求.请求的结果是Id的数组.我想迭代我得到的这个数组并运行另一个http.get请求(函数getItem(id)),然后返回从服务器接收的单个Id的对象.

我试过这样使用它:

  getLatest() {
    return this.http.get('all_news_url')
    .map(res => res.json())
    // I even tried creating Observable from array and get only 5 elements
    //.map(res => Observable.from(res.json()))
    //.take(5)
    .map((data) => this.getItem(data))
    .subscribe(
      data => {
        console.log(data);
      }
    )
  }

  getItem(itemId: any): Observable<any> {
    console.log('item id', itemId);

    return this.http.get(this.generateUrl(`item/${itemId}`))
    .map(res => res.json());
  }
Run Code Online (Sandbox Code Playgroud)

显然,这不起作用.getItem()函数的参数总是作为Id的整个数组传递.

感谢大家参与这个问题.

javascript observable rxjs angularjs

5
推荐指数
1
解决办法
1万
查看次数