Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinAgarwal1337 committed Oct 8, 2018
2 parents 948a7b4 + 99a0e72 commit c9628d6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 106 deletions.
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Google Places API.

This is a PHP wrapper for **Google Places Api Web Service**. And is [Laravel Framework](https://laravel.com/docs/5.2) friendly.
This is a PHP wrapper for **Google Places API Web Service**. And is [Laravel Framework](https://laravel.com/docs/5.2) friendly.

## About Package
With just 2 lines of code you can request to any google places api feature. No need to manually perform any curl requests.
Expand All @@ -16,7 +16,6 @@ With just 2 lines of code you can request to any google places api feature. No n
* [Place Details](#place-details) This service gives more detailed information about a specific Place, including user reviews.
* [Place Autocomplete](#place-autocomplete) This service is Used to automatically fill in the name and/or address of a place as you type.
* [Query Autocomplete](#query-autocomplete) This service is Used to provide a query prediction service for text-based geographic searches, by returning suggested queries as you type.
* [Place Add](#place-add) This service Used to Add/Delete a place to Google's Place database
* [Place Photo](#place-photo) This gives you access to the millions of photos stored in the Google's Places database
* [Additional Methods](#additional-methods) Additional Methods Available.

Expand Down Expand Up @@ -131,13 +130,10 @@ If you are not familiar with <em>Laravel's Collection</em> you can either refere
* `query` — The text string on which to search, for example: "restaurant". The Google Places service will return candidate matches based on this string and order the results based on their perceived relevance.
* `params` - **Optional Parameters** You can refer all the available optional parameters on the [Google's Official Webpage](https://developers.google.com/places/web-service/search)

### radarSearch($location, $radius, array $params)
_**(This method is depricated, and will be removed when google removes it from the api)**_
* `location` — The latitude/longitude around which to retrieve place information. This must be specified as latitude, longitude.
* `radius` — Defines the distance (in meters) within which to return place results. The maximum allowed radius is 50 000 meters.
* `params` - **Optional Parameters** You can refer all the available optional parameters on the [Google's Official Webpage](https://developers.google.com/places/web-service/search)

**Note:** A Radar Search request must include at least one of `keyword`, `name`, or `types`.
### findPlace($input, $inputType, $params = [])
* `input` — The text input specifying which place to search for (for example, a name, address, or phone number).
* `inputType` — The type of input. This can be one of either textquery or phonenumber. Phone numbers must be in international format (prefixed by a plus sign ("+"), followed by the country code, then the phone number itself).
* `params` - **Optional Parameters** You can refer all the available optional parameters on the [Google's Official Webpage](https://developers.google.com/places/web-service/search#FindPlaceRequests)

---

Expand Down Expand Up @@ -165,23 +161,13 @@ _**(This method is depricated, and will be removed when google removes it from t

---

<a name=place-add></a>
# Place Add
### addPlace($params)
_**(This method is depricated, and will be removed when google removes it from the api)**_
* `params` - The set of key-value parameters necessary to add a place to Google. You can refer to the fields on [Google's Official Webpage regarding Place Add](https://developers.google.com/places/web-service/add-place)

### deletePlace($palceId)
_**(This method is depricated, and will be removed when google removes it from the api)**_
* `placeId` - The Place Id you want to delete.

---

<a name=place-photo></a>
# Place Photo
### photo($photoReference, $params = [])
* `params` - The set of key-value parameters necessary to add a place to Google. You can refer to the fields on [Google's Official Webpage regarding Place Add](https://developers.google.com/places/web-service/photos)

---

<a name=additional-methods></a>
# Additional Methods
### getStatus()
Expand Down
111 changes: 26 additions & 85 deletions src/PlacesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PlacesApi

const TEXT_SEARCH_URL = 'textsearch/json';

const RADAR_SEARCH_URL = 'radarsearch/json';
const FIND_PLACE = 'findplacefromtext/json';

const DETAILS_SEARCH_URL = 'details/json';

Expand All @@ -28,6 +28,8 @@ class PlacesApi

const PLACE_PHOTO_URL = 'photo';



/**
* @var
*/
Expand Down Expand Up @@ -66,66 +68,66 @@ public function __construct($key = null, $verifySSL = true)
}

/**
* Place Nearby Search Request to google api.
* Find Place Request to google places api.
*
* @param $location
* @param null $radius
* @param string $input (for example, a name, address, or phone number)
* @param string $inputType (textquery or phonenumber)
* @param array $params
*
* @return \Illuminate\Support\Collection
* @throws \SKAgarwal\GoogleApi\Exceptions\GooglePlacesApiException
*/
public function nearbySearch($location, $radius = null, $params = [])
public function findPlace($input, $inputType, $params = [])
{
$this->checkKey();

$params = $this->prepareNearbySearchParams($location, $radius, $params);
$response = $this->makeRequest(self::NEARBY_SEARCH_URL, $params);
$params['input'] = $input;

return $this->convertToCollection($response, 'results');
$params['inputtype'] = $inputType;

$response = $this->makeRequest(self::FIND_PLACE, $params);

return $this->convertToCollection($response, 'candidates');
}

/**
* Place Text Search Request to google places api.
* Place Nearby Search Request to google api.
*
* @param $query
* @param $location
* @param null $radius
* @param array $params
*
* @return \Illuminate\Support\Collection
* @throws \SKAgarwal\GoogleApi\Exceptions\GooglePlacesApiException
*/
public function textSearch($query, $params = [])
public function nearbySearch($location, $radius = null, $params = [])
{
$this->checkKey();

$params['query'] = $query;
$response = $this->makeRequest(self::TEXT_SEARCH_URL, $params);
$params = $this->prepareNearbySearchParams($location, $radius, $params);
$response = $this->makeRequest(self::NEARBY_SEARCH_URL, $params);

return $this->convertToCollection($response, 'results');

}

/**
* Radar Search Request to google api
*
* @param $location
* @param $radius
* @param $params
* Place Text Search Request to google places api.
*
* @deprecated
* @param $query
* @param array $params
*
* @return \Illuminate\Support\Collection
* @throws \SKAgarwal\GoogleApi\Exceptions\GooglePlacesApiException
*/
public function radarSearch($location, $radius, array $params)
public function textSearch($query, $params = [])
{
$this->checkKey();

$params = $this->prepareRadarSearchParams($location, $radius, $params);

$response = $this->makeRequest(self::RADAR_SEARCH_URL, $params);
$params['query'] = $query;
$response = $this->makeRequest(self::TEXT_SEARCH_URL, $params);

return $this->convertToCollection($response, 'results');

}

/**
Expand Down Expand Up @@ -218,46 +220,6 @@ public function queryAutocomplete($input, $params = [])
return $this->convertToCollection($response, 'predictions');
}

/**
* Adds a place to Google's database
*
* @param $params
*
* @deprecated
*
* @return \Illuminate\Support\Collection
* @throws GooglePlacesApiException
*/
public function addPlace($params)
{
$this->checkKey();

$response = $this->makeRequest(self::PLACE_ADD_URL, $params, 'post');

return $this->convertToCollection($response);
}

/**
* Adds a place to Google's database
*
* @param $placeId
*
* @deprecated
*
* @return \Illuminate\Support\Collection
* @throws GooglePlacesApiException
*/
public function deletePlace($placeId)
{
$this->checkKey();

$params['place_id'] = $placeId;

$response = $this->makeRequest(self::PLACE_DELETE_URL, $params, 'post');

return $this->convertToCollection($response);
}

/**
* @param $uri
* @param $params
Expand Down Expand Up @@ -383,27 +345,6 @@ private function prepareNearbySearchParams($location, $radius, $params)
return $params;
}

/**
* @param $location
* @param $radius
* @param $params
*
* @return mixed
* @throws \SKAgarwal\GoogleApi\Exceptions\GooglePlacesApiException
*/
private function prepareRadarSearchParams($location, $radius, $params)
{
$params['location'] = $location;
$params['radius'] = $radius;

if (!array_any_keys_exists(['keyword', 'name', 'type'], $params)) {
throw new GooglePlacesApiException("Radar Search require one"
. " or more of 'keyword', 'name', or 'type' params.");
}

return $params;
}

/**
* @param bool $verifySSL
*
Expand Down

0 comments on commit c9628d6

Please sign in to comment.