Giter VIP home page Giter VIP logo

googleplace's Introduction

PHP SDK for Google Places APIs

Location aware web application uses google-places-api(Place Search, Place Details, Geocoding , Distance Matrix, Timezone, Elevation ) a lot. They are not linked to each other also its hard to find a easy and time saving php libraray to work with these api. These libraray will need less knowldege about google api and give you flavour of OOP.

Setting

Add this line on your composer.json

"require":{
    "digitaldream/googleplace":"1.*"
}

You need to set your google api keys on top of your page. Like below

   \GooglePlace\Request::$api_key = 'YOUR_GOOGLE_PLACES_API_KEY';

Nearby Search

A Nearby Search lets you search for places within a specified area. For example you can search all the Restaurents of your city.

   $rankBy = new \GooglePlace\Services\Nearby([
            'location' => '23.823168,90.367728',
            'rankby' => 'distance',
            'type' => 'bank'
        ]
    );
    $rankBy->places(); // it will return \Collection each contains a object of GooglePlace\Services\Place
    /* Google Return 60 places divide by 20 each request.
     To get next 20 result you have to call nextPage method.
     */
     print_r($rankBy->nextPage()); // it will return \GooglePlace\Response

Text Search

Text Search Service is a web service that returns information about a set of places based on a string โ€” for example "pizza in New York"

  $textSearch = new \GooglePlace\Services\TextSearch([
  'query' => 'Restaurants in Mirpur'
  ]);
   $places = $textSearch->places(); //same as nearby

Place Details

A Place Details request returns more comprehensive information about the indicated place such as its complete address, phone number, user rating and reviews. You need to pass place_id or a reference from a Place Search

$place=new \GooglePlace\Services\Place([
 'placeid'=>'any place id'
]);
$place->get();
echo $place->address();
echo $place->phone();
print_r($place->photos()); // returns Collection each contains a GooglePlace\Helpers\PlacePhoto object
print_r($place->reviews()); // return Collection
print_r($place->timezone(true)); // return  Timezone API response
print_r($place->distance($place2)); // return Distance Matrix API response
print_r($place->elevation()); // return Elevation API response

Geocoding

You can get places by a place name or latitude and longitude.

 $geocoding = new \GooglePlace\Services\Geocoding([
        'address' => 'House 13,Road 10,Section 11,Mirpur,Dhaka'
    ]);
    print_r($geocoding->places());
    
  $reverseGeocoding=   new \GooglePlace\Services\Geocoding([
        'address' =>  'latlng' => '23.8163589,90.3709893'
    ]);
       print_r($reverseGeocoding->places()); //same as nearby

Distance Matrix API

Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations, based on the recommended route between start and end points

 $distanceMatrix = new \GooglePlace\Services\DistanceMatrix([
        'origins' => ['Dhaka University, Dhaka'],
        'destinations' => ['National University of Bangldesh, Gazipur']]);
        
    print_r($distanceMatrix->calculate());

Timezone API

Time Zone API provides time offset data for locations on the surface of the earth. The API returns the name of that time zone, the time offset from UTC, and the daylight savings offset.

 $timezone= new \GooglePlace\Services\Timezone([
    'location'=>'23.8163589,90.3709893',
    timestamp=time()
 ])
 $response=$timezone->get();
 echo $response->timeZoneId // return Asia/Dhaka

Elevation API

Get the altitude(height from sea level in meters) of a given place.

$elevation =new \GooglePlace\Services\Elevation([
    'locations'=>'23.8163589,90.3709893'
]);
print_r($elevation->get()); 

googleplace's People

Contributors

digitaldreams avatar grycroft avatar ipowerful avatar jacobfogg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

googleplace's Issues

API error response is not returned when using Geocoding

I ran into an error where Geocoding returned null when there was actually an error with my API key and restrictions. I finally found out when debugging the Reponse Class.

How to reproduce

  1. Create an API key that is restricted by http referrers and add a fake domain.
  2. Create a gecoding request (geocode request cannot be restricted by http referers and thus throws an error response)
  3. See that the response is null on Geocoding
  4. When debugging the Response Class you will have a meaningfull error returned.

Class 'Illuminate\Support\Collection' not found

Hi and thank you for this code! I am currently using this in a WordPress project and ran into two issues. I will make to seperate issues to cover this. This one is fairly straightforward.

Class 'Illuminate\Support\Collection' not found

I fixed this by manually requiring illuminate/collections but it would be nice if this library included it in the composer dependencies as well for people not running Laravel.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.