joshtronic/php-googleplaces

Google Places API 的 PHP 封装

1.0.0 2014-09-20 05:57 UTC

This package is auto-updated.

Last update: 2024-08-29 04:03:10 UTC


README

Build Status Coverage Status Downloads Gittip

PHP Wrapper for the Google Places API.

起源

简单来说,当我搜索“php google places”时,我看到了 Google-Places---PHP-。我尝试使用它,并且能够让它工作,但是似乎有一个巨大的假设,即你已经非常了解 Google Places API 的诸多特性。

我不符合这个假设,所以我决定自己构建一个封装器,重点在于对输入进行严格的检查,利用 PHP 的神奇之处(即:你可以直接与对象交互,就像与 API 交互一样),并避免使用setter方法,因为它们被认为是恶魔之作。

我没有选择分支,因为我将改变太多,而且我高度怀疑我的pull请求会被接受。

安装

首选的安装方式是通过 composer。首先在你的 composer.json 中添加以下内容

"require": {
    "joshtronic/php-googleplaces": "dev-master"
}

然后运行 composer update

使用方法

入门指南

$google_places = new joshtronic\GooglePlaces('_YOUR_API_KEY_');

搜索附近的地点,按知名度排序

$google_places->location = array(-33.86820, 151.1945860);
$google_places->radius   = 800;
$results                 = $google_places->nearbySearch();

搜索附近的地点,按距离排序

$google_places->location = array(-33.86820, 151.1945860);
$google_places->rankby   = 'distance';
$google_places->types    = 'restaurant'; // Requires keyword, name or types
$results                 = $google_places->nearbySearch();

附近搜索结果的第二页

$google_places->pagetoken = $results['next_page_token'];
$page2_results            = $google_places->nearbySearch();

雷达搜索

$google_places->location = array(-33.86820, 151.1945860);
$google_places->radius   = 800;
$google_places->types    = 'restaurant'; // Requires keyword, name or types
$results                 = $google_places->radarSearch();

地点详情

$google_places->reference = '#reference#'; // Reference from search results
$details                  = $google_places->details();

未来

我为创建这个库而创建的项目现在已经不再活跃,所以我没有积极使用它或对其进行修改。话虽如此,如果你想要看到某些功能或发现了一个错误,请打开一个问题或直接分支,修改并发送一个pull请求 ;)