Yii 2.0: yii2-google-places-library

Google Places API library for Yii2
3 followers

Introduction

Extension library to interact with Google Places API

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require "2amigos/yii2-google-places-library" "*"

or add

"2amigos/yii2-google-places-library" : "*"

to the require section of your application's composer.json file.

Usage

Using Search class:

$search = new Search(['key' => '{YOURGOOGLEAPIKEY}']);
 
// $this->format = 'xml'; // if you wish to handle XML responses (JSON is highly recommended)
 
 
// If you setup the format in 'xml', the returned value will be an array.
// The library will decode the response automatically
var_dump($search->text('restaurants in Inca Mallorca'));

Using Place class:

$place = new Place(['key' => '{YOURGOOGLEAPIKEY}']);
 
// if you wish to handle XML responses (JSON is highly recommended)
// $this->format = 'xml'; 
 
$place->details('{REFERENCEIDOFPLACE}'));

For further information, check out the great tutorial about geolocation and google places using this library on TutsPlus

Resources

2amigOS!
web development has never been so fun
www.2amigos.us

Total 1 comment

#19419 report it
mannu at 2015/06/29 09:19am
how to view the all 60 results

Thanks for the above code. I have a doubt... I want to see the all 60 results throgh this yii what I tried(below code) is not working.

    $key = 'mykey';
    $search = new Search(['key' => $key]); 

    $res1 = $search->text('Dance Class in Pune');

    if(isset($res1['next_page_token']))
    {
      //1 >> using yii
            //$res2 = $search->text($params=['pagetoken'=>$res1['next_page_token'] ]);   
           //print_r($res2);

//other method echo $placeDetailsURL = 'https://maps.googleapis.com/maps/api/place/textsearch/json?pagetoken='.$res1['next_page_token'].'&key='.$key;

                $placeDetailsContent =file_get_contents($placeDetailsURL);

            $placeDetails = json_decode($placeDetailsContent);

            if ($placeDetails->status == "OK")
                print_r($placeDetails);
            else echo "no result";

what is wrong with my code please help.

thanks manish

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet