0

Using the Google Places API, you can only get 20 results back from a single query ... so you can't query for ALL results at once, but rather need to store what has already been searched for (in an array) and add to that array or remove from that array...

This demonstrates my question ... I need to be able to add places to my array, but then search through the array and remove any places that are no longer needed.

Is there a "compare array" function that I should be utilizing, or perhaps something better? I just feel that's quite rudimentary... and perhaps I'm missing some Google API function that's obvious.

My plan is to create an object:

var placesObj = {};

And since all places can have multiple "types", I need to be able to push each place id into an array WITHIN the placesObj like so:

var placesObj = {
    bars: {'123123123123123', '123123123355555', '12312312132123'},
    parks: {'123123123123123', '123123123355555', '12312312132123'}
};

This way, I can look for the id string and remove it from the entire placesObj ...

I hope this makes sense... I just need to know how to construct this object.

4

1 に答える 1

0

http://php.net/manual/en/function.array-diff.phpが役に立ちます。2番目の配列には存在しない配列1のすべてのエントリを含む配列を返します。これで、それに応じてアレイを変更できるようになります。

編集:これで、phpではなくjavascriptを参照していることが明らかになり、別の会話になりました。JSオブジェクトを比較し、それに応じて更新する場合は、キーと値のペアを使用して、次のように削除します。

var placesObj = {
    bars: {'tavern': '123123123123123', 'bar123':'123123123355555', 'blahblah':'12312312132123'},
    parks: {'jungle' : '123123123123123', 'kidspar;':'123123123355555', 'foo': '12312312132123'}
}; 

delete placesObj['tavern']; 
delete placesObj['yourKey']; 

Googleからjson応答を取得し、その応答からこのオブジェクトを構築していると想定しています...おそらく、Googleから取得している他の一意の値を使用して、場所の名前などのキーを作成できます。

于 2013-02-22T21:40:41.117 に答える