PHPackages                             abivia/geocoding - 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. abivia/geocoding

ActiveLibrary

abivia/geocoding
================

Geocoding support.

3.1.0(6mo ago)350↓100%[1 issues](https://github.com/abivia/geocoding/issues)MITPHPPHP ^8.2

Since Aug 11Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/abivia/geocoding)[ Packagist](https://packagist.org/packages/abivia/geocoding)[ RSS](/packages/abivia-geocoding/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (15)Used By (0)

Abivia Geocoding
================

[](#abivia-geocoding)

The Abivia geocoding library provides a caching interface to IP address lookup APIs from these sources:

- ipinfo.io
- ipstack.com
- ipapi.co

The library supports both IPv4 and IPv6 addresses and is designed to seamlessly support other IP address geocoding services.

Requirements
------------

[](#requirements)

Geocoding requires:

- PHP 8.2 or higher
- ext-curl to perform API calls
- abivia/cogs for address support
- mlocati/ip-lib for IP address support

PHP does not need to be built with IPv6 support.

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

[](#installation)

Via composer:

`composer require abivia/geocoding`

Caching
-------

[](#caching)

Geocoding comes with two cache handlers designed for light use and a database cache for heavier use. The array cache will retain lookup results for the lifetime of the current request (or session if stored in a session variable). The file cache stores cached data in a text file. Neither offers support for concurrent requests.

The PDO Cache takes a connection to a database, optionally with table names to override the default tables `geocoder_cache_ip`, `geocoder_cache_subnet` and `geocoder_cache_options`. The cache handler will create these tables if they do not already exist.

Applications can create persistent caches by conforming to the CacheHandler interface. Caches support different retention times for lookup hits and lookup misses. In a file cache, the default retention time for a successful lookup is seven days, the default retention time for a failed lookup is one hour. The PDO cache defaults to 30 days for a successful lookup and one hour for a failed lookup.

### Cache Purging

[](#cache-purging)

Array caches are expected to be transient, so there is no purge logic. The file cache runs a purge at the time the cache is loaded. The PDO cache runs at the interval set by the `purgeCacheTime()` method, which defaults to 24 hours. On the first object creation, the last purge time is loaded from the database and cached in the session to reduce overhead.

Sample Usage
------------

[](#sample-usage)

```
use Abivia\Geocode\Geocoder;
use Abivia\Geocode\LookupService\IpInfoApi;

$geocoder = new Geocoder(IpInfoApi::make());
$info = $geocoder->lookup('4.4.4.4');
echo $info->getLatitude() . ', ' . $info->getLongitude();
```

The geocoder normalizes results from different services using the GeocodeResult interface, but applications can retrieve the service's response through the GeocodeResult::data() method to access extended information.

Example using a file cache
--------------------------

[](#example-using-a-file-cache)

```
use Abivia\Geocode\CacheHandler\FileCache;
use Abivia\Geocode\Geocoder;
use Abivia\Geocode\LookupService\IpInfoApi;

// Get a cache and set the cache time for a hit to six hours
$cache = new FileCache('mycache.json');
$cache->hitCacheTime(6 * 3600);
$geocoder = new Geocoder(IpInfoApi::make(), $cache);
$info = $geocoder->lookup('4.4.4.4');
echo $info->getLatitude() . ', ' . $info->getLongitude();
```

Subnet queries
--------------

[](#subnet-queries)

For the most part from a geolocation perspective, only the first 24 bits of an IPv4 and the first 48 of an IPv6 address are significant. Geocoding provides a "subnet" query that will return the last queries result in the v4 or v6 range. This can reduce the number of queries on the lookup service, increasing performance and (in the case of paid services) reducing costs.

### Subnet Example

[](#subnet-example)

```
use Abivia\Geocode\Geocoder;
use Abivia\Geocode\LookupService\IpInfoApi;

$geocoder = new Geocoder(IpInfoApi::make());

// Assume 4.4.4.4 is not currently cached. This will cause the service to be queried.
$info = $geocoder->lookupSubnet('4.4.4.4');
echo $info->getLatitude() . ', ' . $info->getLongitude();

// This query will return the cached data for 4.4.4.4
$info2 = $geocoder->lookupSubnet('4.4.4.8');
```

Donations welcome
-----------------

[](#donations-welcome)

If you're getting something out of Geocoding, you can sponsor us in any amount you wish using Liberapay [![Liberapay](https://camo.githubusercontent.com/f42d4c8650291eed95d5feb7658604d653ad107d3308fb7e8f269623d7ed65cf/68747470733a2f2f6c69626572617061792e636f6d2f6173736574732f776964676574732f646f6e6174652e737667)](https://liberapay.com/abivia/donate). Liberapay is itself run on donations and takes no fees beyond bank charges.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance59

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~89 days

Recently: every ~71 days

Total

14

Last Release

204d ago

Major Versions

1.0.1 → 2.0.02022-08-17

2.6.0 → 3.0.02025-10-06

PHP version history (2 changes)1.0.0PHP ^8.1

2.2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/42cd72dce530e94e60853407cdab69ead232423272b482218ae686c740ce0e99?d=identicon)[abivia](/maintainers/abivia)

---

Top Contributors

[![instancezero](https://avatars.githubusercontent.com/u/2599327?v=4)](https://github.com/instancezero "instancezero (21 commits)")

---

Tags

geocodeabivia

### Embed Badge

![Health badge](/badges/abivia-geocoding/health.svg)

```
[![Health](https://phpackages.com/badges/abivia-geocoding/health.svg)](https://phpackages.com/packages/abivia-geocoding)
```

###  Alternatives

[spatie/geocoder

Geocoding addresses to coordinates

8404.8M15](/packages/spatie-geocoder)[anthonymartin/geo-location

Powerful GeoCoding library: Retrieve bounding box coordinates, distances between geopoints, point in polygon, get longitude and latitude from addresses and more with GeoLocation for PHP

196949.5k5](/packages/anthonymartin-geo-location)[yandex/geo

PHP-library for interactions with geo-coding Yandex.Maps

117309.0k3](/packages/yandex-geo)[mediawiki/maps

Adds various mapping features to MediaWiki

84145.0k3](/packages/mediawiki-maps)[opencage/geocode

A PHP library for geocoding via the OpenCage Geocoder API

37480.0k4](/packages/opencage-geocode)[abivia/ledger

General Ledger and Journal Accounting Package for Laravel with JSON API

12934.9k](/packages/abivia-ledger)

PHPackages © 2026

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