mil/google-places

此包已被废弃且不再维护。未建议替代包。

PHP封装的Google Places API

v1.2 2018-02-02 22:50 UTC

This package is not auto-updated.

Last update: 2022-12-15 22:56:15 UTC


README

PHP封装的Google Places API。基于André Nosalsky创建的GPLV2类。

基本用法

<?php
require_once('googlePlaces.php');

$apiKey       = 'Your Google Places API Key';
$googlePlaces = new googlePlaces($apiKey);

// Set the longitude and the latitude of the location you want to search near for places
$latitude   = '-33.8804166';
$longitude = '151.2107662';
$googlePlaces->setLocation($latitude . ',' . $longitude);

$googlePlaces->setRadius(5000);
$results = $googlePlaces->search(); //

可以使用API最近添加的“分页”功能再次运行搜索查询以获取一组新的结果。

要使用它,只需按正常方式执行地点搜索,然后调用返回“next_page_token”元素的第一次搜索后的重复方法,例如。

$firstSearch = $googlePlaces->Search();

if (!empty($firstSearch['next_page_token'])) {
	$secondSearch = $googlePlaces->repeat($firstSearch['next_page_token']);
}

重复函数可以在每个搜索功能中使用两次,每个搜索请求最多可提供60个单独的结果。

代理

当您使用部署服务器并且每次运行新构建时都会更改IP地址时,您可能希望只通过一个IP地址发送请求。因此,您可以在Google Developers Console 服务器密钥中只允许该单个IP。为此,您应设置代理以通过该代理路由您的Google Maps API请求。

当您的代理设置好时,您可以使用它与googlePlaces一起使用。

$proxy = [];
$proxy["host"] = "your host name";
$proxy["port"] = 8080;
$proxy["username"] = "your username"; //optional with password
$proxy["password"] = "your password";
$apiKey       = 'Your Google Places API Key';
$googlePlaces = new googlePlaces($apiKey, $proxy);