1. Go to this page and download the library: Download chris48s/cakephp-geocoder 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/ */
chris48s / cakephp-geocoder example snippets
namespace App\Controller;
use App\Controller\AppController;
class StoresController extends AppController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Chris48s/Geocoder.Geocoder');
}
public function search()
{
$location = $this->request->query['location'];
$geocodeResult = $this->Geocoder->geocode($location);
if (count($geocodeResult) > 0) {
$latitude = floatval($geocodeResult[0]->geometry->location->lat);
$longitude = floatval($geocodeResult[0]->geometry->location->lng);
}
}
}
namespace App\Model\Table;
use Cake\ORM\Table;
class Stores extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->addBehavior('Chris48s/Geocoder.Geocodable');
}
}
namespace App\Model\Table;
use Cake\ORM\Table;
class Stores extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->addBehavior('Chris48s/Geocoder.Geocodable', [
'addressColumn' => 'street_address',
'latitudeColumn' => 'lat',
'longitudeColumn' => 'lng'
]);
}
}
namespace App\Model\Table;
use Cake\ORM\Table;
class Stores extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->addBehavior('Chris48s/Geocoder.Geocodable', [
'addressColumn' => [
'street_address',
'locality',
'postal_code'
]
]);
}
}
namespace App\Model\Table;
use Cake\ORM\Table;
class Stores extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->addBehavior('Chris48s/Geocoder.Geocodable', [
'