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应该对您有所帮助。它将返回一个数组,其中包含数组 1 中不存在于第二个数组中的所有条目。然后,您应该能够相应地修改您的数组。

编辑:现在很明显您引用的是javascript,而不是php,这是一个不同的对话。如果我要比较 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 回答