lquintana/google-places-popular-times

获取具有自己流行时间的谷歌地点,适用于 Laravel >= 5.8

v1.0.1 2020-08-28 17:46 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:28 UTC


README

The MIT License Latest Version on Packagist Total Downloads Laravel

介绍

使用此包,您可以获取具有其流行时间的地点列表,或者也可以获取具有其流行时间的地点详情。结果还将包括特定时间的流行时间和百分比。

遵循谷歌API文档了解其要求,并使用此包 https://developers.google.com/places/web-service/intro

要求

  • >= PHP 7.1
  • >= Laravel 5.8

安装

通过 Composer

$ composer require lquintana/google-places-popular-times

配置

您需要从谷歌控制台创建一个密钥,并授予其使用地点API的权限。将以下变量添加到您的 Laravel 项目的 .env 文件中,并将字符串 YOUR-GOOGLE-KEY 替换为谷歌密钥。

GOOGLE_API_KEY=YOUR-GOOGLE-KEY

使用以下 artisan 命令发布配置文件

php artisan vendor:publish --tag="googlepopulartimes"

使用方法

以下是一个获取流行地点列表的示例 URL。 http://places.test/api/places?location=26.189774,-80.103775&radius=5000&keyword=restaurants

您应该在 route/api.php 中添加 routes/places 路由,或者在项目的任何方便位置创建路由

@ 这是我的 Laravel 控制器的一个示例。您可以看到 index 方法,它将列出每个地点的流行时间。

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use LQuintana\GooglePopularTime\Facades\GooglePopularTime;

class PlaceController extends Controller
{
    /**
     * @params $request
     * Return list of places with its popular time.
     */
    public function index(Request $request)
    {
        $data = $request->all();
        $places = GooglePopularTime::getNearbyPlacesWithPopularTimes($data);
        return response()->json($places, 200);
    }
}

以下是一些使用前一个方法的截图。

screen shot 2019-02-25 at 9 49 53 am




如果您打开流行时间键,它包含一周中的所有日子。

screen shot 2019-02-25 at 9 49 27 am



screen shot 2019-02-25 at 9 51 21 am

  • 请注意,谷歌地点API需要至少 location=26.189774,-80.103775&radius=5000 参数。
  • 查看以下链接中的谷歌文档了解更多关于允许的参数的信息。 https://developers.google.com/places/web-service/search

这是获取具有其流行时间的地点的示例 URL。 http://places.test/api/places/ChIJ5z2kxpsB2YgRjUgd_WuWdWc

谷歌地点API所需的最小参数是 placeid,例如 placeid=ChIJde9xlp4B2YgRVl9hn3TriiI

  • 有关更多详细信息,请参阅谷歌文档。 https://developers.google.com/places/web-service/details

@ 下面的代码是 Laravel 控制器的一个示例。您可以看到 index 方法,它将列出每个地点的流行时间,以及 show 方法,它将仅显示一个地点的流行时间。

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use LQuintana\GooglePopularTime\Facades\GooglePopularTime;

class PlaceController extends Controller
{
    /**
     * @params $request
     * Return place with its popular time.
     */
    public function show(Request $request, $place)
    {
        $placeDetails = GooglePopularTime::getPlaceDetailsWithPopularTimes($place);
        return response()->json($placeDetails, 200);
    }
}

这是获取具有其流行时间的地点的示例 URL。 http://places.test/api/places/ChIJ5z2kxpsB2YgRjUgd_WuWdWc

  • 不要忘记创建路由。

在结果中,您可以找到该时间的流行时间和百分比。 screen shot 2020-08-28 at 9 51 21 am

如果您只想获取不带流行时间的地点列表,这是方法

<?php

GooglePopularTime::getNearbyPlaces($data);

如果您只想获取不带流行时间的地点详情,这是方法

<?php

GooglePopularTime::getPlaceDetails($placeId);

贡献

请参阅 contributing.md 了解详细信息和一个待办事项列表。

安全

如果您发现任何与安全相关的问题,请通过作者电子邮件而不是使用问题跟踪器。

鸣谢

许可协议

许可协议。有关更多信息,请参阅 许可文件