This package provides a simple framework-independent geocoding library.
Install the library using Composer:
composer require 1tomany/php-geocoderA Symfony bundle is available if you wish to integrate this library into your Symfony applications with autowiring and configuration support.
- Mock
use OneToMany\Geocoder\Bridge\Google\GoogleProvider;
use OneToMany\Geocoder\Bridge\Mock\MockProvider;
use OneToMany\Geocoder\Bridge\Transport;
use OneToMany\Geocoder\GeocoderClient;
use OneToMany\Geocoder\Resource\Geocode;
use OneToMany\Geocoder\Resource\Reverse;
use OneToMany\Geocoder\Vendor;
$transport = new Transport(
createSymfonyHttpClient(),
createSymfonySerializer(),
);
$googleApiKey = getenv('GOOGLE_API_KEY');
$geocoderClient = new GeocoderClient([
new GoogleProvider(
transport: $transport,
apiKey: $googleApiKey,
),
new MockProvider(),
]);
$response = $geocoderClient->geocode(
Vendor::Google,
new Geocode(
street: '123 Main Street',
unit: null,
city: 'Dallas',
zip: '75205',
state: 'TX',
country: null,
),
);
$response = $geocoderClient->reverse(
Vendor::Google,
new Reverse(
latitude: 32.10391494,
longitude: -96.3931030,
),
);The MIT License