Installation
composer require amf/foursquare-bundle
Register the bundle in config/bundles.php (Symfony 4+):
return [
// ...
Amf\FourSquareBundle\AmfFourSquareBundle::class => ['all' => true],
];
Configuration
Add Foursquare API credentials to config/packages/amf_foursquare.yaml:
amf_foursquare:
client_id: '%env(FOURSQUARE_CLIENT_ID)%'
client_secret: '%env(FOURSQUARE_CLIENT_SECRET)%'
First Use Case: Scanning Venues
Inject the VenueScanner service in a controller:
use Amf\FourSquareBundle\Service\VenueScanner;
class LocationController extends AbstractController
{
public function scanVenues(VenueScanner $scanner)
{
$venues = $scanner->scan('40.7128° N, 74.0060° W', 1000); // Lat/Lon + radius (meters)
return $this->json($venues);
}
}
Venue Discovery
VenueScanner for proximity-based searches:
$scanner->scan($latitude, $longitude, $radius, $limit = 20);
$scanner->scanWithCategory($lat, $lon, $radius, '4d4b7105d48988d1066d1fe3');
Service Integration
VenueType (if provided by the bundle).VenueScanner to cache responses (e.g., with Symfony Cache component):
$cache = $this->container->get('cache.app');
$cachedVenues = $cache->get('venues_' . $lat . '_' . $lon);
Event-Driven Extensions
// Example (hypothetical event)
$dispatcher->addListener('amf_foursquare.venue.scanned', function ($event) {
$event->getVenues()->filter(fn($v) => $v['price'] > 50);
});
Deprecated API
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.foursquare.com/v2/venues/search', [
'query' => [
'client_id' => $this->config['client_id'],
'client_secret' => $this->config['client_secret'],
'v' => '20230601',
'll' => $lat . ',' . $lon,
'radius' => $radius,
]
]);
No Modern Symfony Support
# config/services.yaml
Amf\FourSquareBundle\Service\VenueScanner:
decorates: 'amf_foursquare.venue_scanner'
arguments: ['@Amf\FourSquareBundle\Service\VenueScanner.inner']
Missing Documentation
Resources/doc folder is empty in the repo. Refer to:
API Rate Limits
use Symfony\Component\HttpClient\RetryableHttpClient;
$client = new RetryableHttpClient(
new \Symfony\Contracts\HttpClient\HttpClient(),
[
'max_retries' => 3,
'delay' => 1000, // 1 second
]
);
Response Validation
$response = json_decode($client->getResponse()->getContent(), true);
if (!isset($response['response']['venues'])) {
throw new \RuntimeException('Invalid Foursquare API response');
}
Custom Venue Models
class VenueMapper
{
public function map(array $foursquareData): Venue
{
return new Venue(
id: $foursquareData['id'],
name: $foursquareData['name'],
location: $foursquareData['location']['address'] ?? null
);
}
}
Geocoding Integration
$geocoder = new \Geocoder\Provider\GoogleMaps\Provider();
$coordinates = $geocoder->geocode('1600 Amphitheatre Parkway');
$venues = $scanner->scan($coordinates->getLatitude(), $coordinates->getLongitude(), 1000);
Testing
VenueScanner in tests:
$this->container->set('amf_foursquare.venue_scanner', $this->createMock(VenueScanner::class));
How can I help you explore Laravel packages today?