PHPackages                             sjaakp/yii2-spatial - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. sjaakp/yii2-spatial

ActiveYii2-extension[Database &amp; ORM](/categories/database)

sjaakp/yii2-spatial
===================

Yii2 ActiveRecord supporting MySQL spatial data

1.1.2(1y ago)1873.8k↑54.3%9[5 issues](https://github.com/sjaakp/yii2-spatial/issues)[1 PRs](https://github.com/sjaakp/yii2-spatial/pulls)1MITPHPPHP &gt;=5.5.0

Since Nov 21Pushed 1y ago3 watchersCompare

[ Source](https://github.com/sjaakp/yii2-spatial)[ Packagist](https://packagist.org/packages/sjaakp/yii2-spatial)[ RSS](/packages/sjaakp-yii2-spatial/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (1)

Yii2-spatial
============

[](#yii2-spatial)

[![Latest Stable Version](https://camo.githubusercontent.com/8969de787992bfe1a451c955b42dd0aa46019a70cbbbd906abb67c3a45edacbf/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7370617469616c2f762f737461626c65)](https://packagist.org/packages/sjaakp/yii2-spatial)[![Total Downloads](https://camo.githubusercontent.com/1e2b13a4a4ad2d84c68ad9ff4d0129181867cd6a6e9f108d7974e38583298664/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7370617469616c2f646f776e6c6f616473)](https://packagist.org/packages/sjaakp/yii2-spatial)[![License](https://camo.githubusercontent.com/958537b2fcb753894babe9b5fdd2a4d2936479d87e09403eef47769ab63fcfd4/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7370617469616c2f6c6963656e7365)](https://packagist.org/packages/sjaakp/yii2-spatial)

ActiveRecord with spatial attributes. Those attributes are transformed from the internal [MySQL format](https://dev.mysql.com/doc/refman/8.0/en/spatial-types.html) to [GeoJSON format](https://geojson.org/) after finding, and vice versa before storing.

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

**Notice that this extension is intended to be used with a MySQL or MariaDB database exclusively.**

Version 1.1.0 is compatible with MySQL 5.7 and MariaDB 10.3.

Installation
------------

[](#installation)

Install **Yii2-spatial** with [Composer](https://getcomposer.org/). Either add the following to the require section of your `composer.json` file:

`"sjaakp/yii2-spatial": "*"`

Or run:

`composer require sjaakp/yii2-spatial "*"`

You can manually install **Yii2-spatial** by [downloading the source in ZIP-format](https://github.com/sjaakp/yii2-spatial/archive/master.zip).

Usage
-----

[](#usage)

Simply use a `sjaakp\spatial\ActiveRecord` as base class for your models, like so:

```
