PHP code example of osynapsy / geocoding
1. Go to this page and download the library: Download osynapsy/geocoding 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/ */
osynapsy / geocoding example snippets
use Osynapsy\Geocoding\Geocoder;
use Osynapsy\Geocoding\Provider\Nominatim;
use Osynapsy\Geocoding\Provider\Google;
use Osynapsy\Geocoding\Provider\OpenCage;
$geocoder = new Geocoder([
new Nominatim(),
new Google('GOOGLE_API_KEY'),
new OpenCage('OPENCAGE_API_KEY')
]);
$location = $geocoder->locate('Via Roma 10, Milano');
if ($location) {
echo $location->lat . ',' . $location->lng;
}
public function getCoordinates(string $address): ?Location;