A Laravel package for interacting with the Google Places API. This package allows you to search for cities, states, nearby shops, restaurants, and other places based on user input or geographic coordinates.
- Search Places: Autocomplete feature to search cities, states, and places based on a query.
- Nearby Places: Find nearby shops, restaurants, and more based on latitude, longitude, and a radius.
You can install this package via Composer by running the following command in your Laravel project:
composer require avcodewizard/google-place-api
Add your Google Places API Key to your .env file:
GOOGLE_PLACES_API_KEY=your_google_places_api_key
You can use the GooglePlacesApiService to search for cities, states, or other places via query.
use Avcodewizard\GooglePlaceApi\GooglePlacesApi;
class PlaceController extends Controller
{
public function searchPlace(Request $request,GooglePlacesApi $googlePlaces)
{
$query = $request->input('query');
$results = $this->googlePlaces->searchPlace($query);
return response()->json($results);
}
}
You can find nearby places like restaurants, shops, etc., using geographic coordinates (latitude and longitude) along with a search radius.
public function nearbyPlaces(Request $request)
{
$latitude = $request->input('latitude');
$longitude = $request->input('longitude');
$radius = $request->input('radius');
$type = $request->input('type'); // Optional: e.g., 'restaurant', 'store'
$results = $this->googlePlaces->findNearbyPlaces($latitude, $longitude, $radius, $type);
return response()->json($results);
}
- PHP 7.3 or higher
- Laravel 8.x or higher
- Google Place API key
Feel free to report issues or make Pull Requests. If you find this document can be improved in any way, please feel free to open an issue for it.