PHP code example of sparefoot / geocoder
1. Go to this page and download the library: Download sparefoot/geocoder 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/ */
sparefoot / geocoder example snippets
$adapter = new \Http\Adapter\Guzzle6\Client();
$provider = new \Geocoder\Provider\GoogleMaps($adapter);
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'en');
$geocoder->geocode(...);
$geocoder->reverse(...);
// configure you geocoder object
$stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();
$geocoder = new \Geocoder\TimedGeocoder($geocoder, $stopwatch);
$geocoder->geocode('Paris, France');
// Now you can debug your application
$geocoder = new \Geocoder\Provider\GoogleMaps(
$httpAdapter,
$locale,
$region,
$useSsl, // true|false
$apiKey
);
$geocoder->setLocale('xyz');
$locale = $geocoder->getLocale();
php
$geocoder = new \Geocoder\ProviderAggregator();
$geocoder->registerProviders([
new \Geocoder\Provider\GoogleMaps(
$adapter, $locale, $region, $useSsl
),
new \Geocoder\Provider\GoogleMapsBusiness(
$adapter, '<CLIENT_ID>', '<PRIVATE_KEY>', $locale, $region, $useSsl
),
new \Geocoder\Provider\Yandex(
$adapter, $locale, $toponym
),
new \Geocoder\Provider\MaxMind(
$adapter, '<MAXMIND_API_KEY>', $service, $useSsl
),
new \Geocoder\Provider\ArcGISOnline(
$adapter, $sourceCountry, $useSsl
),
]);
$geocoder->registerProvider(
new \Geocoder\Provider\Nominatim(
$adapter, 'http://your.nominatim.server', $locale
)
);
$geocoder
->using('google_maps')
->geocode('...');
$geocoder
->limit(10)
->reverse($lat, $lng);
php
$addresses = $geocoder
->registerProvider(new \My\Provider\Custom($adapter))
->using('custom')
->limit(10)
->geocode('68.145.37.34')
;
php
$geocoder = new \Geocoder\ProviderAggregator();
$adapter = new \Http\Adapter\Guzzle6\Client();
$chain = new \Geocoder\Provider\Chain([
new \Geocoder\Provider\FreeGeoIp($adapter),
new \Geocoder\Provider\HostIp($adapter),
new \Geocoder\Provider\GoogleMaps($adapter, 'fr_FR', 'France', true),
new \Geocoder\Provider\BingMaps($adapter, '<API_KEY>'),
// ...
]);
$geocoder->registerProvider($chain);
try {
$geocode = $geocoder->geocode('10 rue Gambetta, Paris, France');
var_export($geocode);
} catch (Exception $e) {
echo $e->getMessage();
}
php
$dumper = new \Geocoder\Dumper\Gpx();
$strGpx = $dumper->dump($address);
echo $strGpx;
php
// $address is an instance of Address
$formatter = new \Geocoder\Formatter\StringFormatter();
$formatter->format($address, '%S %n, %z %L');
// 'Badenerstrasse 120, 8001 Zuerich'
$formatter->format($address, '<p>%S %n, %z %L</p>');
// '<p>Badenerstrasse 120, 8001 Zuerich</p>'
xml
<php>
<!-- <server name="IPINFODB_API_KEY" value="YOUR_API_KEY" /> -->
<!-- <server name="BINGMAPS_API_KEY" value="YOUR_API_KEY" /> -->
<!-- <server name="GEOIPS_API_KEY" value="YOUR_API_KEY" /> -->
<!-- <server name="MAXMIND_API_KEY" value="YOUR_API_KEY" /> -->
<!-- <server name="GEONAMES_USERNAME" value="YOUR_USERNAME" /> -->
<!-- <server name="TOMTOM_MAP_KEY" value="YOUR_MAP_KEY" /> -->
<!-- <server name="GOOGLE_GEOCODING_KEY" value="YOUR_GEOCODING_KEY" /> -->
<!-- <server name="OPENCAGE_API_KEY" value="YOUR_API_KEY" /> -->
</php>