PHP code example of getkirby / geo

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

    

getkirby / geo example snippets


Geo::point(49.4883333, 8.4647222);
Geo::point('49.4883333, 8.4647222');
Geo::point([49.4883333, 8.4647222]);
Geo::point(['lat' => 49.4883333, 'lng' => 8.4647222]);

$point = Geo::point(49.4883333, 8.4647222);
echo $point->lat();
echo $point->lng();

$mannheim = Geo::point(49.4883333, 8.4647222);
$hamburg  = Geo::point(53.553436, 9.992247);

echo 'The distance between Mannheim and Hamburg is: ' . Geo::distance($mannheim, $hamburg);

echo 'The distance between Mannheim and Hamburg is: ' . Geo::distance($mannheim, $hamburg, 'mi');

$mannheim = Geo::point(49.4883333, 8.4647222);
$hamburg  = Geo::point(53.553436, 9.992247);

echo 'The distance between Mannheim and Hamburg is: ' . Geo::niceDistance($mannheim, $hamburg);

echo 'The distance between Mannheim and Hamburg is: ' . Geo::niceDistance($mannheim, $hamburg, 'mi');

echo Geo::kilometersToMiles(1000);

echo Geo::milesToKilometers(1000);

$addresses = page('addresses')->children()->filterBy('location', 'radius', [
  'lat'    => 49.4883333,
  'lng'    => 8.4647222,
  'radius' => 10
]);

$addresses = page('addresses')->children()->filterBy('location', 'radius', [
  'lat'    => 49.4883333,
  'lng'    => 8.4647222,
  'radius' => 10,
  'unit'   => 'mi'
]);

$page->location()->coordinates()->lat();
$page->location()->coordinates()->lng();

$hamburg = Geo::point(53.553436, 9.992247);

echo $page->location()->distance($hamburg);

$hamburg = Geo::point(53.553436, 9.992247);

echo $page->location()->distance($hamburg, 'mi');

$hamburg = Geo::point(53.553436, 9.992247);

echo $page->location()->niceDistance($hamburg);