PHP code example of shumex / geocode
1. Go to this page and download the library: Download shumex/geocode 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/ */
shumex / geocode example snippets
try {
$response = Geocode::make()->address('Saporischschja', 'de');
if ($response) {
echo $response->latitude();
echo "<br>";
echo $response->longitude();
echo "<br>";
echo $response->formattedAddress();
echo "<br>";
}
} catch (GeoException $exception) {
echo $exception->getMessage();
}
// Output
// 35.139567
// 47.8388
// Saporischschja, Ukraine, 69061
try {
$response = Geocode::make()->latLng(47.850437, 35.135653, 'en');
if ($response) {
echo $response->latitude();
echo "<br>";
echo $response->longitude();
echo "<br>";
echo $response->formattedAddress();
echo "<br>";
}
} catch (GeoException $exception) {
echo $exception->getMessage();
}
// Output
// 47.850437
// 35.135653
// Volhohrads'ka St, 27, Zaporizhzhia, Zaporiz'ka oblast, Ukraine, 69000
try {
$response = Geocode::make()->latLng(40.7637931,-73.9722014);
if ($response) {
echo $response->raw()->address_components[8]['types'][0];
echo $response->raw()->address_components[8]['long_name'];
}
} catch (GeoException $exception) {
echo $exception->getMessage();
}
// Output
// postal_code
// 10153