Download the PHP package reza-id/yii2-geopoint without Composer

On this page you can find all versions of the php package reza-id/yii2-geopoint. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-geopoint

Yii2-geopoint

ActiveRecord inspired by yii2-spatial but made simpler only to use specific spatial datatype: POINT.
Transform the internal MySQL format to simple coordinate text after finding, and vice versa before storing.

Yii2-geopoint can also be used to find the model or models which are nearest to a given location.

Notice that this extension can be used with MySQL >= 5.6.1, MariaDB >= 5.3.3, and PostgreSQL >= 9.1.

Installation

Install Yii2-geopoint with Composer. Either add the following to the require section of your composer.json file:

"reza-id/yii2-geopoint": "*"

Or run:

$ php composer.phar require reza-id/yii2-geopoint "*"

You can manually install Yii2-geopoint by downloading the source in ZIP-format.

Usage

Create spatial indexed table using migration:

$this->createTable('{{%place}}', [
    'id' => $this->primaryKey(),
    'name' => $this->string(125)->notNull(),
    'location' => 'POINT NOT NULL',
], $tableOptions);

if ($this->db->driverName === 'mysql') {
    $this->execute('CREATE SPATIAL INDEX `idx-place-location` ON '.'{{%place}}(location);');
} elseif ($this->db->driverName === 'pgsql') {
    $this->execute('CREATE INDEX "idx-place-location" ON '.'{{%place}} USING GIST(location);');
}

Use a rezaid\geopoint\ActiveRecord as base class for your models, like so:

<?php
namespace app\models;

use rezaid\geopoint\ActiveRecord;

class MyModel extends ActiveRecord
{
    // ...
}

Notice: if you override find() in a rezaid\geopoint\ActiveRecord-derived class, be sure to return a rezaid\geopoint\ActiveQuery and not an 'ordinary' yii\db\ActiveQuery.

ActiveQuery method

nearest()

public function nearest($from, $attribute, $radius, $unit)

Change the query so that it finds the model(s) nearest to the point given by $from.

Example usages:

$here = '4.9,52.3';     // longitude and latitude of my place

$nearestModel = <model>::find()->nearest($here, <attributeName>, 200, 'mil')->one();    // search radius is 200 miles

$fiveNearestModels =  <model>::find()->nearest($here, <attributeName>)->limit(5)->all();    // search radius is 100 km (default)

$dataProvider = new ActiveDataProvider([ 'query' => <model>::find()->nearest($here, <attributeName>) ]);

ActiveRecord method

getDistance()

Get the distance from given location in the ActiveQuery method nearest(), if you want to display the distance in RESTful API, add this as new field in your model:

<?php
namespace app\models;

use rezaid\geopoint\ActiveRecord;

class MyModel extends ActiveRecord
{

    // ...

    public function fields()
    {
        $fields = parent::fields();

        $fields['distance'] = function ($model) {
            return $model->getDistance();
        };

        return $fields;
    }

    // ...

}

Example rest controller:

<?php
namespace app\controllers;

use Yii;
use yii\rest\ActiveController;

class PlaceController extends ActiveController
{
    public $modelClass = 'app\models\MyModel';

    public function actionSearch()
    {
        $from = Yii::$app->request->get('from');
        $model = new $this->modelClass;
        $query = $model->find();

        if (!empty($from)) {
            $query->nearest($from, 'location', 200);
        }

        try {
            $provider = new \yii\data\ActiveDataProvider([
                'query' => $query,
            ]);
        } catch (Exception $ex) {
            throw new \yii\web\HttpException(500, 'Internal server error');
        }

        if ($provider->getCount() <= 0) {
            throw new \yii\web\HttpException(404, 'No entries found');
        } else {
            return $provider;
        }
    }
}

All versions of yii2-geopoint with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package reza-id/yii2-geopoint contains the following files

Loading the files please wait ....