PHP code example of francoisvaillant / geolocator

1. Go to this page and download the library: Download francoisvaillant/geolocator 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/ */

    

francoisvaillant / geolocator example snippets


$place = new Place()

$place = new Place(NominatimProvider::class)

$place
    ->setAddress('your address');
    ->setCity('city name');
    ->setZipCode(00000);
    ->geolocate();

$latitude  = $place->getLatitude();  // NULL if geolocation failed
$longitude = $place->getLongitude(); // NULL if geolocation failed

$place
    ->setLatitude(45.548);
    ->setLongitude(1.897);
    ->reverse();

$address = $place->getAddress(); // NULL if reverse failed
$zipCode = $place->getZipCode(); // NULL if reverse failed
$city    = $place->getCity();    // NULL if reverse failed

$place
    ->setLatitude(45.548);
    ->setLongitude(1.897);
    ->findAltitude() 
    ->getAltitude(); // NULL if failed

    $altitudeProvider = new AltitudeProvider('http://localhost:5000/v1/srtm30m?locations=%s,%s'); // note that first %s is for latitude, second one is for longitude
    $place->setAltitudeProvider($altitudeProvider);

    if($place->geolocate()) {
        // ...
    }

    if($place->reverse()) {
        // ...
    }

$place
    //...
    ->geolocate();
$place->getProvider()->getResponseData();

$place
    //...
    ->reverse();
$place->getProvider()->getResponseData();

$place
    //...
    ->findAltitude();
$place->getAltitudeProvider()->getResponseData();