PHPackages                             openbuildings/jam-locations - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. openbuildings/jam-locations

ActiveKohana-module[Utility &amp; Helpers](/categories/utility)

openbuildings/jam-locations
===========================

Geoip and IP integration

0.2.1(6y ago)1170.7k2BSD-3-ClausePHPPHP ^7.1CI failing

Since Sep 25Pushed 6y ago11 watchersCompare

[ Source](https://github.com/OpenBuildings/jam-locations)[ Packagist](https://packagist.org/packages/openbuildings/jam-locations)[ Docs](https://github.com/OpenBuildings/jam-locations)[ RSS](/packages/openbuildings-jam-locations/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (8)Used By (2)

Jam Locations
=============

[](#jam-locations)

[![Build Status](https://camo.githubusercontent.com/1e06cb39f037777f08edbc8e51192da0fbf985788ac7aa08a895a58c78a93bd8/68747470733a2f2f7472617669732d63692e6f72672f4f70656e4275696c64696e67732f6a616d2d6c6f636174696f6e732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/OpenBuildings/jam-locations)[![Coverage Status](https://camo.githubusercontent.com/2b5035f8de3fd21a7c8deb8e3529e3187261281e880ac0be16dd19b1138c4920/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f4f70656e4275696c64696e67732f6a616d2d6c6f636174696f6e732f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/OpenBuildings/jam-locations?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/d1fc4bd353208f62fff809c3d5a95207d57d9cefeec7dcf2f93d34ca119ccf27/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e6275696c64696e67732f6a616d2d6c6f636174696f6e732f762f737461626c652e706e67)](https://packagist.org/packages/openbuildings/jam-locations)

This module adds hierarchical locations (continents, countries, cities), by leveraging openbuildings/jam-closuretable. As well as auto initialized ip field and countries / cities set automatically through geolocation.

Usage
-----

[](#usage)

Using ip field is as easy as just defining it:

```
class Model_User extends Jam_Model {

	public static function initialize(Jam_Meta $meta)
	{
		$meta
			->fields(array(
				// ...
				'ip' => Jam::field('ip'),
			));
	}
}

$user = Jam::build('user');
echo $user->ip; // will return the current ip address (from Request::$clent_ip)
```

Auto Location is a bit more involved:

```
class Model_User extends Jam_Model {

	public static function initialize(Jam_Meta $meta)
	{
		$meta
			->behaviors(array(
				'location_auto' => Jam::behavior('location_auto', array(
					'locations' => array(
						// association => geoip record name
						'city' => 'city',
						'country' => 'country_name',
					)
				)),
			))
			->associations(array(
				'country' => Jam::association('belongsto', array('foreign_model' => 'location')),
				'city' => Jam::association('belongsto', array('foreign_model' => 'location')),
			))
			->fields(array(
				'id' => Jam::field('primary'),
				'ip' => Jam::field('ip'),
			));
	}
}
```

Then if you do not set city or country association, it would use the ip field to get a geoip record, and from there try to find / create the appropriate location.

Lastly the location\_parent behavior is used to assign a parent to a location association if both the child and the parent are present in the model:

```
class Model_Address extends Jam_Model {

	public static function initialize(Jam_Meta $meta)
	{
		$meta
			->behaviors(array(
				'location_parent' => Jam::behavior('location_parent', array(
					'parents' => array(
						// child => parent
						'city' => 'country',
					)
				)),
			))
			->associations(array(
				'country' => Jam::association('belongsto', array('foreign_model' => 'location')),
				'city' => Jam::association('belongsto', array('foreign_model' => 'location')),
			))
			->fields(array(
				'id' => Jam::field('primary'),
			));
	}
}

$address = Jam::build('address');

$address->country = Jam::find('location', 'France');
$address->city = Jam::build('location', array('name' => 'Paris'));

$address->save();

echo $address->city->parent->name(); // will return "France"
```

Requirement
-----------

[](#requirement)

This module requires php geoip extension.

License
-------

[](#license)

Copyright (c) 2012-2013, OpenBuildings Ltd. Developed by **Ivan Kerin** as part of [clippings.com](http://clippings.com)

Under BSD-3-Clause license, read LICENSE file.

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~587 days

Total

5

Last Release

2259d ago

PHP version history (3 changes)0.1.0PHP &gt;=5.4.0

0.1.2PHP &gt;=5.3.0

0.2.0PHP ^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/506129?v=4)[Harry Dobrev](/maintainers/hkdobrev)[@hkdobrev](https://github.com/hkdobrev)

![](https://avatars.githubusercontent.com/u/4113307?v=4)[Danail Kyosev](/maintainers/dkyosev)[@dkyosev](https://github.com/dkyosev)

![](https://avatars.githubusercontent.com/u/7592650?v=4)[Evstati Zarkov](/maintainers/EZarkov)[@EZarkov](https://github.com/EZarkov)

![](https://avatars.githubusercontent.com/u/745771?v=4)[Filip Georgiev](/maintainers/phgeorgiev)[@phgeorgiev](https://github.com/phgeorgiev)

![](https://avatars.githubusercontent.com/u/490439?v=4)[Zdravko Evstatiev](/maintainers/zedevs)[@zedevs](https://github.com/zedevs)

---

Top Contributors

[![hkdobrev](https://avatars.githubusercontent.com/u/506129?v=4)](https://github.com/hkdobrev "hkdobrev (10 commits)")[![bozhidargyurov](https://avatars.githubusercontent.com/u/36644891?v=4)](https://github.com/bozhidargyurov "bozhidargyurov (2 commits)")[![ivank](https://avatars.githubusercontent.com/u/4976?v=4)](https://github.com/ivank "ivank (1 commits)")[![sstoyanov7](https://avatars.githubusercontent.com/u/9350596?v=4)](https://github.com/sstoyanov7 "sstoyanov7 (1 commits)")[![tumbalev](https://avatars.githubusercontent.com/u/28398671?v=4)](https://github.com/tumbalev "tumbalev (1 commits)")

---

Tags

geoipkohanalocationcountrycity

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/openbuildings-jam-locations/health.svg)

```
[![Health](https://phpackages.com/badges/openbuildings-jam-locations/health.svg)](https://phpackages.com/packages/openbuildings-jam-locations)
```

###  Alternatives

[torann/geoip

Support for multiple Geographical Location services.

2.2k14.2M77](/packages/torann-geoip)[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[dipeshsukhia/laravel-country-state-city-data

Country State City Data Provider

8230.8k](/packages/dipeshsukhia-laravel-country-state-city-data)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[kartik-v/yii2-ipinfo

An IP address information display widget for Yii 2.0 with country flag and geo position info.

2832.6k1](/packages/kartik-v-yii2-ipinfo)[tabgeo/country

geoip (only countries) php library (http://tabgeo.com)

1158.8k](/packages/tabgeo-country)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
