Google Maps Place Details (Reviews)
The PlaceDetails class is a part of the Designbycode namespace and is used to fetch reviews, rating, and user ratings total of a place using the Google Places API. It requires a Google Maps API key and a Google Maps place ID to make requests.
Package Documentation
This package provides a simple and easy-to-use interface for fetching place details from the Google Maps Place Details API.
Please note the package only return 5 reviews at most.
Google Maps Place Search API
If you want to fetch more reviews, please use the
Installation
To install the package, use composer:
composer require designbycode/google-maps-place-details
Usage
To use the package, you need to provide a Google Maps API key and a place ID:
use Designbycode\GoogleMapsPlaceDetails\PlaceDetails;
$placeDetails = new PlaceDetails('YOUR_API_KEY', 'YOUR_PLACE_ID');
You can then fetch the full result set from the Google Maps API:
$results = $placeDetails->getResults();
Or you can fetch specific data, such as reviews, rating, and user ratings total:
$reviews = $placeDetails->getReviews();
$rating = $placeDetails->getRating();
$userRatingTotal = $placeDetails->getUserRatingTotal();
Fields
The package supports the following fields:
- reviews
- rating
- user_ratings_total
$placeDetails = new PlaceDetails('YOUR_API_KEY', 'YOUR_PLACE_ID');
Results Class
The Results
class is responsible for handling the results of a Google Maps Place Details API request. It provides the following methods:
-
reviews()
: Returns an array of reviews from the API response. -
rating()
: Returns the rating from the API response, or null if not present. -
userRatingsTotal()
: Returns the total number of user ratings from the API response, or null if not present.
Example
$placeDetails = new PlaceDetails('YOUR_API_KEY', 'YOUR_PLACE_ID');
$placeDetails->getResults()->reviews();
Enum Class
The Field enum class is used to define the fields that can be fetched from the Google Maps Place Details API. It supports the following fields:
- reviews
- rating
- user_ratings_total
Testing
composer test
Contributors
License
This project is licensed under the MIT License - see the LICENSE file for details.