arraypress / wp-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.
Requires
- php: >=8.3
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13.5
- wp-coding-standards/wpcs: ^3.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Turn an address into coordinates, and back, using Maps.co — free at low volume and no card required.
What it does
Same job as Google's Geocoding API, from a service you can use without a billing account. Maps.co is built on OpenStreetMap data: less precise than Google on individual buildings, entirely adequate for a town, a postcode or a delivery radius.
The response is an object with named methods, and lookups are cached, since an address does not move.
Features
- Turn a written address into latitude and longitude
- Turn coordinates back into a display address
- Get map links for Google, Apple, Bing and OpenStreetMap without building URLs
- Read the OpenStreetMap type and id behind a result
- Cache lookups for as long as suits, and clear one on demand
- Start without a billing account, which Google's equivalent requires
Installation
composer require arraypress/wp-mapsco-geocoding
Quick start
Geocode an address when it is saved:
use ArrayPress\MapsCo\Geocoding\Client; $client = new Client( $api_key ); $result = $client->geocode( 'Buckingham Palace, London' ); if ( ! is_wp_error( $result ) ) { update_post_meta( $id, '_lat', $result->get_latitude() ); update_post_meta( $id, '_lng', $result->get_longitude() ); }
And a link somebody can actually open:
echo esc_url( $result->get_google_maps_url() );
What it does not do
It will not reliably find a specific flat in a building, or a new-build street.
For that, Google's Geocoding API is worth the billing account —
arraypress/wp-google-geocoding is the same shape.
Requirements
- PHP 8.3 or later
- WordPress 7.1 or later
- A Maps.co API key (free tier, no card)
License
GPL-2.0-or-later