PHPackages                             arraypress/mapsco-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. [API Development](/categories/api)
4. /
5. arraypress/mapsco-geocoding

ActiveLibrary[API Development](/categories/api)

arraypress/mapsco-geocoding
===========================

A PHP library for integrating with the Maps.co Geocoding API in WordPress, providing both forward and reverse geocoding capabilities with WordPress transient caching.

13PHP

Since Jan 6Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Maps.co API Geocoding Library for WordPress
===========================================

[](#mapsco-api-geocoding-library-for-wordpress)

A WordPress library for Maps.co Geocoding API integration with smart caching and comprehensive location data handling.

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

[](#installation)

Install via Composer:

```
composer require arraypress/mapsco-geocoding
```

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

[](#requirements)

- PHP 7.4 or later
- WordPress 6.2.2 or later
- Maps.co API key

Basic Usage
-----------

[](#basic-usage)

```
use ArrayPress\MapsCo\Geocoding\Client;

// Initialize with your API key
$client = new Client( 'your-api-key-here' );

// Forward geocoding (address to coordinates)
$location = $client->geocode( '1600 Pennsylvania Avenue NW, Washington, DC' );

// Reverse geocoding (coordinates to address)
$location = $client->reverse_geocode( 38.8977, -77.0365 );
```

Available Methods
-----------------

[](#available-methods)

### Client Methods

[](#client-methods)

```
// Initialize client with options
$client = new Client(
	'your-api-key-here',  // API key
	'json',              // Response format (optional, default: 'json')
	true,               // Enable caching (optional, default: true)
	604800             // Cache duration in seconds (optional, default: 1 week)
);

// Forward geocoding
$location = $client->geocode( '1600 Pennsylvania Avenue NW, Washington, DC' );

// Reverse geocoding
$location = $client->reverse_geocode( 38.8977, - 77.0365 );

// Cache management
$client->clear_cache( 'address_key' );  // Clear specific cache
$client->clear_cache();                 // Clear all cached geocoding data
```

### Location Methods

[](#location-methods)

```
// Get coordinates
$lat = $location->get_latitude();   // Returns: 38.8977
$lon = $location->get_longitude();  // Returns: -77.0365

// Get formatted address
$display_name = $location->get_display_name();
// Returns: "White House, 1600, Pennsylvania Avenue Northwest, Washington, DC 20500"

// Get address components
$house_number = $location->get_house_number();  // Returns: "1600"
$street       = $location->get_street();             // Returns: "Pennsylvania Avenue Northwest"
$city         = $location->get_city();                // Returns: "Washington"
$state        = $location->get_state();              // Returns: "District of Columbia"
$postcode     = $location->get_postcode();        // Returns: "20500"
$country      = $location->get_country();          // Returns: "United States"
$country_code = $location->get_country_code(); // Returns: "US"
$borough      = $location->get_borough();          // Returns: "Ward 2"

// Get OpenStreetMap data
$place_id = $location->get_place_id();   // Returns: OSM place ID
$osm_type = $location->get_osm_type();   // Returns: "way"
$osm_id   = $location->get_osm_id();       // Returns: OSM ID

// Get location type information
$class = $location->get_class();  // Returns: e.g., "office"
$type  = $location->get_type();    // Returns: e.g., "government"

// Get importance ranking
$importance = $location->get_importance();  // Returns: float value

// Get license information
$license = $location->get_license();  // Returns: license text

// Get bounding box
if ( $location->has_bounding_box() ) {
	$bbox = $location->get_bounding_box();
	// Returns: [
	//     'min_lat' => float,
	//     'max_lat' => float,
	//     'min_lon' => float,
	//     'max_lon' => float
	// ]
}
```

### Raw Data Access

[](#raw-data-access)

```
// Get complete raw data array
$raw_data = $location->get_raw_data();
```

Response Format Examples
------------------------

[](#response-format-examples)

### Forward Geocoding Response

[](#forward-geocoding-response)

```
[
    'place_id' => 308584984,
    'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0.',
    'osm_type' => 'way',
    'osm_id' => 238241022,
    'lat' => '38.897699700000004',
    'lon' => '-77.03655315',
    'display_name' => 'White House, 1600, Pennsylvania Avenue Northwest, Ward 2, Washington, District of Columbia, 20500, United States',
    'class' => 'office',
    'type' => 'government',
    'importance' => 1.05472115416811,
    'boundingbox' => [
        '38.8974908',
        '38.897911',
        '-77.0368537',
        '-77.0362519'
    ]
]
```

### Reverse Geocoding Response

[](#reverse-geocoding-response)

```
[
    'place_id' => 308584984,
    'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0.',
    'osm_type' => 'way',
    'osm_id' => 238241022,
    'lat' => '38.897699700000004',
    'lon' => '-77.03655315',
    'display_name' => 'White House, 1600, Pennsylvania Avenue Northwest, Ward 2, Washington, District of Columbia, 20500, United States',
    'address' => [
        'office' => 'White House',
        'house_number' => '1600',
        'road' => 'Pennsylvania Avenue Northwest',
        'borough' => 'Ward 2',
        'city' => 'Washington',
        'state' => 'District of Columbia',
        'postcode' => '20500',
        'country' => 'United States',
        'country_code' => 'us'
    ],
    'boundingbox' => [
        '38.8974908',
        '38.897911',
        '-77.0368537',
        '-77.0362519'
    ]
]
```

Error Handling
--------------

[](#error-handling)

The library uses WordPress's `WP_Error` for error handling:

```
$location = $client->geocode( 'invalid address' );

if ( is_wp_error( $location ) ) {
    echo $location->get_error_message();
    // Output: "No results found for the provided address"
}
```

Common error cases:

- Invalid address
- Invalid coordinates
- Invalid API key
- API request failure
- No results found
- Invalid response format

Contributions
-------------

[](#contributions)

Contributions to this library are highly appreciated. Raise issues on GitHub or submit pull requests for bug fixes or new features. Share feedback and suggestions for improvements.

License: GPLv2 or later
-----------------------

[](#license-gplv2-or-later)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (18 commits)")

---

Tags

wordpress-librarywordpress-php-librarywordpress-plugin-library

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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