开发者

Google Local Search PHP to Javascript

My apologies in advance, this question may not be the clearest, but I will try my best to articulate.

In my PHP script I'm processing a string. I want to grab whatever is in between brackets [ ] and execute a google local search (see http://code.google.com/apis/ajax/playground/#show_driving_directions) on the string. Once the search is processed I wa开发者_Python百科nt to only grab the first result.

Just as a background, I have the PHP script executing anytime a "message" comes in.

I have all the regex stuff working, just need to know what the flow would be to call the google search api and return the first result.


I would suggest calling the AJAX API directly, and parsing the result from JSON into an object (json_decode()) and taking the first result.

See the API docs at the following parts,

http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_urlbase http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_args http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_local

I've personally been working on some classes that wrap around the AJAX API, but they're no where near finished (probably going to refactor them for better structure).

You can however grab the current source from my SVN if you want. I've done the Local search and it works in its current form.

http://codelib.stephenmelrose.co.uk/svn/php/branches/1.0/library/

You'd use it like,

require_once("library/google/search/Local.php");

$google_search = new SM_Google_Search_Local('starbucks');
$google_search->setHTTPReferer("http://localhost.localhost/");
$google_search->setResultSetSize(Google_Search::RESULT_SET_SIZE_LARGE);
$google_search->setCenterPoint('53.79548,-1.549416');

$response = $google_search->getResponse();
$results = $response->getResults();

// Your first result
$results[0];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜