Skip to content

1quintana/google-places-popular-times

Repository files navigation

GooglePopularTime for Laravel

The MIT License Latest Version on Packagist Total Downloads Laravel

Introduction

Using this package you can get a list of places with its popular times or also a place details with its popular times. Time and percentage of popularity for certain time is also included in the results.

Follow the google API documentation to understand their requirements and use this package https://developers.google.com/places/web-service/intro

Requirements

  • >= PHP 7.1
  • >= Laravel 5.8

Installation

Via Composer

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

Configuration

You need to create a google key from the google console give it the rigth permisions to use places API. Add the following variables to the .env file in your project Laravel and replace the string YOUR-GOOGLE-KEY for the google key.

GOOGLE_API_KEY=YOUR-GOOGLE-KEY

Publish the config file with following artisan command

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

Usage

Here there is an example of url when trying to get a list of popular places. http://places.test/api/places?location=26.189774,-80.103775&radius=5000&keyword=restaurants

You should add the route places to route/api.php or create the route in any convinient location for your project

@ This is an example of my controller in Laravel. You can find the method index which will list places with its own popular time for each of them

<?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);
    }
}

Here Some screenshots with the result from the previous method.

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




if you open the key popular times it contains all the days of the week

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



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

  • Keep in mind that Google Places API require location=26.189774,-80.103775&radius=5000 as minimum parameters.
  • Check the Google documentation in the following link to know more about the allowed parameters. https://developers.google.com/places/web-service/search

This is an example of the url to get a place with its own popular times. http://places.test/api/places/ChIJ5z2kxpsB2YgRjUgd_WuWdWc

Google Places API Minimum params required placeid, ex placeid=ChIJde9xlp4B2YgRVl9hn3TriiI

  • Refer to google documentation for more details. https://developers.google.com/places/web-service/details

@ The next code is an example of my controller in Laravel. You can find the method index which list places with its own popular time for each of them and the method show to show only one place with its own popular times.

<?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);
    }
}

This is an example of the url to get a place with its own popular times. http://places.test/api/places/ChIJ5z2kxpsB2YgRjUgd_WuWdWc

  • Do not forget to create the route.

In the results you can find the time and percentage of popularity in that time. screen shot 2020-08-28 at 9 51 21 am

If you just want a list of places without popular time this is the method

<?php

GooglePopularTime::getNearbyPlaces($data);

If you just want a place details without popular time this is the method

<?php

GooglePopularTime::getPlaceDetails($placeId);

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

license. Please see the license file for more information.