PHP code example of avcodewizard / google-place-api

1. Go to this page and download the library: Download avcodewizard/google-place-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

avcodewizard / google-place-api example snippets


use Avcodewizard\GooglePlaceApi\GooglePlacesApi;

class PlaceController extends Controller
{

    public function searchPlace(Request $request)
    {
        $query = $request->input('query');
        $googlePlaces = new GooglePlacesApi();
        $results = $googlePlaces->searchPlace($query);

        return response()->json($results);
    }
}

public function placeDetails($placeId)
{
    $placeApi = new GooglePlacesApi();
    $results = $placeApi->getPlaceDetails($placeId);

    return response()->json($results);
}

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);
}