PHPackages                             arraypress/google-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/google-geocoding

ActiveLibrary[API Development](/categories/api)

arraypress/google-geocoding
===========================

A PHP library for integrating with the Google Geocoding API in WordPress, providing address to coordinate conversion and structured address information. Features WordPress transient caching and WP\_Error support.

03PHP

Since Jan 6Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Google Geocoding API for WordPress
==================================

[](#google-geocoding-api-for-wordpress)

A PHP library for integrating with the Google Geocoding API in WordPress, providing address to coordinate conversion and structured address information. Features WordPress transient caching and WP\_Error support.

Features
--------

[](#features)

- 🗺️ **Address Geocoding**: Convert addresses to coordinates
- 📍 **Reverse Geocoding**: Convert coordinates to addresses
- 🏠 **Address Components**: Access structured address information
- ⚡ **WordPress Integration**: Native transient caching and WP\_Error support
- 🛡️ **Type Safety**: Full type hinting and strict types
- 🔄 **Response Parsing**: Clean response object for easy data access
- 🌍 **Global Support**: Works with addresses worldwide
- 📐 **Viewport Information**: Access location viewport bounds
- 🏢 **Business Detection**: Identify business locations
- 🔍 **Detailed Components**: Access neighborhood and sublocality information
- 📋 **Multiple Result Types**: Handle various location types
- ✨ **Plus Code Support**: Access global and compound plus codes

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

[](#requirements)

- PHP 7.4 or later
- WordPress 5.0 or later
- Google Geocoding API key

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

[](#installation)

Install via Composer:

```
composer require arraypress/google-geocoding
```

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

[](#basic-usage)

```
use ArrayPress\Google\Geocoding\Client;

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

// Forward geocoding (Address to Coordinates)
$result = $client->geocode( '1600 Amphitheatre Parkway, Mountain View, CA' );
if ( ! is_wp_error( $result ) ) {
	$coordinates = $result->get_coordinates();
	echo "Latitude: {$coordinates['latitude']}\n";
	echo "Longitude: {$coordinates['longitude']}\n";
}

// Reverse geocoding (Coordinates to Address)
$result = $client->reverse_geocode( 37.4220, - 122.0841 );
if ( ! is_wp_error( $result ) ) {
	echo $result->get_formatted_address();
}
```

Extended Examples
-----------------

[](#extended-examples)

### Getting Structured Address Components

[](#getting-structured-address-components)

```
$result = $client->geocode( '1600 Amphitheatre Parkway, Mountain View, CA' );
if ( ! is_wp_error( $result ) ) {
	$address = $result->get_structured_address();

	// Basic Components
	$street       = $result->get_street_number() . ' ' . $result->get_street_name();
	$city         = $result->get_city();
	$state        = $result->get_state();
	$state_code   = $result->get_state_short();
	$postal       = $result->get_postal_code();
	$country      = $result->get_country();
	$country_code = $result->get_country_short();

	// Additional Components
	$neighborhood        = $result->get_neighborhood();
	$sublocality         = $result->get_sublocality();
	$sublocality_level_1 = $result->get_sublocality_level_1();
}
```

### Working with Business Locations

[](#working-with-business-locations)

```
$result = $client->geocode( '123 Business Street' );
if ( ! is_wp_error( $result ) ) {
	if ( $result->is_business_location() ) {
		echo "This is a business location\n";
	}

	// Get all place types
	$types = $result->get_types();

	// Get specific components by types
	$business_components = $result->get_address_components_by_types( [ 'establishment', 'point_of_interest' ] );
}
```

### Handling Plus Codes and Location Types

[](#handling-plus-codes-and-location-types)

```
$result = $client->geocode( '1600 Amphitheatre Parkway, Mountain View, CA' );
if ( ! is_wp_error( $result ) ) {
	// Plus Codes
	$plus_code = $result->get_plus_code();
	echo "Compound Code: " . $result->get_plus_code_compound() . "\n";
	echo "Global Code: " . $result->get_plus_code_global() . "\n";

	// Location Type
	$location_type = $result->get_location_type(); // ROOFTOP, RANGE_INTERPOLATED, etc.

	// Viewport Information
	$viewport = $result->get_viewport();
	if ( $viewport ) {
		echo "Northeast: {$viewport['northeast']['lat']}, {$viewport['northeast']['lng']}\n";
		echo "Southwest: {$viewport['southwest']['lat']}, {$viewport['southwest']['lng']}\n";
	}
}
```

### Handling Responses with Caching

[](#handling-responses-with-caching)

```
// Initialize with custom cache duration (1 hour = 3600 seconds)
$client = new Client( 'your-api-key', true, 3600 );

// Results will be cached
$result = $client->geocode('1600 Amphitheatre Parkway, Mountain View, CA');

// Clear specific cache
$client->clear_cache('geocode_1600 Amphitheatre Parkway, Mountain View, CA');

// Clear all geocoding caches
$client->clear_cache();
```

### Working with Multiple Results

[](#working-with-multiple-results)

```
$result = $client->geocode( 'Springfield' );
if ( ! is_wp_error( $result ) ) {
	// Get all results
	$all_results = $result->get_results();

	// Iterate over results with a callback
	$locations = $result->iterate_results( function ( $location ) {
		return [
			'address'     => $location['formatted_address'],
			'coordinates' => $location['geometry']['location']
		];
	} );
}
```

API Methods
-----------

[](#api-methods)

### Client Methods

[](#client-methods)

- `geocode( $address )`: Convert address to coordinates
- `reverse_geocode( $lat, $lng )`: Convert coordinates to address
- `clear_cache( $identifier = null )`: Clear cached responses

### Response Methods

[](#response-methods)

#### Basic Information

[](#basic-information)

- `get_all()`: Get complete raw response data
- `get_first_result()`: Get first result from response
- `get_results()`: Get all results from response
- `get_status()`: Get API response status

#### Address Information

[](#address-information)

- `get_formatted_address()`: Get full formatted address
- `get_structured_address()`: Get all components in structured format
- `is_partial_match()`: Check if result is a partial match
- `is_business_location()`: Check if location is a business/POI

#### Geographic Information

[](#geographic-information)

- `get_coordinates()`: Get latitude/longitude array
- `get_latitude()`: Get latitude
- `get_longitude()`: Get longitude
- `get_viewport()`: Get viewport bounds
- `get_location_type()`: Get location type (ROOFTOP, etc.)
- `get_types()`: Get all place types

#### Plus Codes

[](#plus-codes)

- `get_plus_code()`: Get plus code information
- `get_plus_code_compound()`: Get compound plus code
- `get_plus_code_global()`: Get global plus code

#### Place Information

[](#place-information)

- `get_place_id()`: Get Google Place ID

#### Address Components

[](#address-components)

- `get_street_number()`: Get street number
- `get_street_name()`: Get street name
- `get_neighborhood()`: Get neighborhood
- `get_sublocality()`: Get sublocality
- `get_sublocality_level_1()`: Get sublocality level 1
- `get_city()`: Get city/locality
- `get_county()`: Get county
- `get_state()`: Get state/province
- `get_state_short()`: Get state/province code
- `get_postal_code()`: Get postal code
- `get_country()`: Get country
- `get_country_short()`: Get country code

#### Component Helpers

[](#component-helpers)

- `get_address_component( $type )`: Get specific address component
- `get_address_component_short( $type )`: Get specific address component short name
- `get_address_components()`: Get all address components
- `get_address_components_by_types( array $types )`: Get components matching multiple types

#### Result Processing

[](#result-processing)

- `iterate_results( callable $callback )`: Process all results with a callback

Use Cases
---------

[](#use-cases)

- **Address Validation**: Verify and standardize addresses
- **Coordinate Lookup**: Get coordinates for addresses
- **Location Services**: Support location-based features
- **Address Parsing**: Extract address components
- **Geographic Analysis**: Analyze location data
- **Map Integration**: Support for mapping features
- **Address Autocomplete**: Base for address lookup systems
- **Business Location Detection**: Identify commercial locations
- **Neighborhood Analysis**: Access detailed area information
- **Multiple Result Handling**: Process ambiguous locations

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the GPL-2.0-or-later License.

Support
-------

[](#support)

- [Documentation](https://github.com/arraypress/google-geocoding)
- [Issue Tracker](https://github.com/arraypress/google-geocoding/issues)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity3

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 (12 commits)")

---

Tags

wordpress-developmentwordpress-php-library

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/arraypress-google-geocoding/health.svg)](https://phpackages.com/packages/arraypress-google-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)
