PHP code example of germania-kg / geodata

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

    

germania-kg / geodata example snippets



use Germania\GeoData\GeoDataProviderInterface;

/**
 * @return null|GeoDataInterface
 */
public function getGeoData();


use Germania\GeoData\GeoDataInterface;

/**
 * @return float|null
 */
public function getLatitude();

/**
 * @return float|null
 */
public function getLongitude();


/**
 * @return float[]
 */
public function getLatLon();

/**
 * @return string|null
 */
public function getSource();

/**
 * @return string|null
 */
public function getStatus();


use Germania\GeoData\GeoDataProviderTrait;

class MyGeoDataProvider
{
	use GeoDataProviderTrait;
}

$object = new MyGeoDataProvider;

// Property or GeoDataProviderInterface method
$object->geodata;
$object->getGeoData();



use Germania\GeoData\GeoDataAbstract;

class MyGeoData extends GeoDataAbstract
{
	use GeoDataTrait;
}

$object = new MyGeoData;

// Properties
echo $object->latitude;
echo $object->longitude;

// GeoDataProviderInterface methods
echo $object->getLatitude();
echo $object->getLongitude();
$coords = $object->getLatLon();


use Germania\GeoData\GeoData;  

// "Null" object
$geo = new GeoData();
$coords = $object->getLatLon();    // [ null, null]
$coords = $object->getLatitude();  // null
$coords = $object->getLongitude(); // null
echo $geo->getSource(); // null

// With real data
$latitude = 54.0;
$longitude = 10.0;
$description = "provided by Google Maps";

$geo = new GeoData( $latitude, $longitude, $description);
$geo->setSource("Corrected manually");
$get->setStatus("Not too exact");

$coords = $object->getLatLon(); // [ 54.0, 10.0]
echo $geo->getSource(); // "Corrected manually"


use Germania\GeoData\GeoDataFactory;  
use Germania\GeoData\GeoData;  

$factory = new GeoDataFactory;

// All these fields default to null
$geodata = $factory([
  'latitude'  => 54, 
  'longitude' => 10, 
  'source' => "Test case", 
  'status' => "OK"  
]);


use Germania\GeoData\GuzzleGeoDataFactory;
use GuzzleHttp\Client as GuzzleClient;

$guzzle = new GuzzleClient( ... );
$factory = new GuzzleGeoDataFactory($guzzle);

$geodata = $factory->fromString("Musterstraße 1, 12345 Musterstadt");
echo get_class( $geodata ); // Germania\GeoData\GeoData


use Germania\GeoData\GeoDataExceptionInterface;
use Germania\GeoData\GeoDataFactoryRuntimeException;

// For 404 ClientExceptions, extends GeoDataFactoryRuntimeException
use Germania\GeoData\GeoDataFactoryNotFoundException;