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

ActiveLibrary[API Development](/categories/api)

arraypress/google-maps-embed
============================

A PHP library for integrating with the Google Maps Embed API in WordPress, providing interactive map embeds with support for places, searches, directions, and street view. Features WordPress error handling and customizable iframe generation.

06PHP

Since Jan 6Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Google Maps Embed API for WordPress
===================================

[](#google-maps-embed-api-for-wordpress)

A PHP library for integrating with the Google Maps Embed API in WordPress, providing easy-to-use methods for embedding Google Maps with various modes including places, search, directions, street view, and standard views. Features WordPress integration, method chaining, and `WP_Error` support.

Features
--------

[](#features)

- 🗺️ **Multiple Embed Modes**: Support for places, search, directions, view, and street view
- 📍 **Place Integration**: Embed maps using Google Place IDs
- 🔍 **Search Support**: Embed maps with search queries
- 🚗 **Directions**: Show routes between locations
- 🏠 **Street View**: Embed street-level imagery
- ⚡ **WordPress Integration**: Native WP\_Error support and escaping
- 🛡️ **Type Safety**: Full type hinting and strict types
- 🎨 **Customizable**: Flexible iframe attributes and styling options
- 🌍 **Global Support**: Works with locations worldwide
- 🔐 **Secure**: Built-in security features including referrer policy
- 📱 **Responsive**: Support for responsive iframe attributes
- ✨ **Easy Implementation**: Simple, intuitive API methods
- 🔄 **Method Chaining**: Fluent interface for setting options
- ⚙️ **Validation**: Built-in parameter validation for all setters

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

[](#requirements)

- PHP 7.4 or later
- WordPress 5.0 or later
- Google Maps Embed API key

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

[](#installation)

Install via Composer:

```
composer require arraypress/google-maps-embed
```

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

[](#basic-usage)

```
use ArrayPress\Google\MapsEmbed\Client;

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

// Configure options using method chaining
$client
    ->set_mode( 'driving' )
    ->set_units( 'imperial' )
    ->set_zoom( 15 )
    ->set_language( 'en' );

// Embed a place using Place ID
$place_url = $client->place( 'ChIJN1t_tDeuEmsRUsoyG83frY4' );
$iframe = $client->generate_iframe( $place_url );

// Embed a search result
$search_url = $client->search( 'Coffee shops in Seattle' );
$iframe = $client->generate_iframe( $search_url );

// Embed directions
$directions_url = $client->directions( 'Seattle, WA', 'Portland, OR' );
$iframe = $client->generate_iframe( $directions_url );
```

Configuration Methods
---------------------

[](#configuration-methods)

### Setting Options

[](#setting-options)

```
// Travel mode
$client->set_mode( 'driving|walking|bicycling|transit' );

// Map type
$client->set_map_type( 'roadmap|satellite' );

// Units
$client->set_units( 'metric|imperial' );

// Route avoidance
$client->set_avoid( ['tolls', 'highways', 'ferries'] );

// Zoom level (0-21)
$client->set_zoom( 15 );

// Street view settings
$client->set_heading( 90 );    // 0-360 degrees
$client->set_pitch( -30 );     // -90 to 90 degrees
$client->set_fov( 60 );        // 10-100 degrees

// Localization
$client->set_language( 'en' );
$client->set_region( 'US' );

// API key management
$client->set_api_key( 'new-api-key' );
```

### Getting Options

[](#getting-options)

```
// Get current settings
$mode = $client->get_mode();
$map_type = $client->get_map_type();
$units = $client->get_units();
$avoid = $client->get_avoid();
$zoom = $client->get_zoom();
$heading = $client->get_heading();
$pitch = $client->get_pitch();
$fov = $client->get_fov();
$language = $client->get_language();
$region = $client->get_region();
$api_key = $client->get_api_key();

// Get all options
$all_options = $client->get_options();

// Reset options to defaults
$client->reset_options();
```

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

[](#extended-examples)

### Embedding a Place

[](#embedding-a-place)

```
$client = new Client( 'your-api-key' );

// Basic place embed
$place_url = $client
	->set_zoom( 15 )
	->set_language( 'en' )
	->place( 'ChIJN1t_tDeuEmsRUsoyG83frY4' );

// Generate iframe with custom attributes
$iframe = $client->generate_iframe( $place_url, [
	'width'  => '800',
	'height' => '600',
	'class'  => 'my-custom-map'
] );
```

### Working with Different View Types

[](#working-with-different-view-types)

```
// Standard view using coordinates
$view_url = $client
	->set_zoom( 12 )
	->set_map_type( 'satellite' )
	->view( 47.6062, - 122.3321 );

// Street view with camera settings
$street_url = $client
	->set_heading( 90 )
	->set_pitch( 10 )
	->set_fov( 75 )
	->streetview( 47.6062, - 122.3321 );

// Search with specific parameters
$search_url = $client
	->set_zoom( 13 )
	->set_language( 'en' )
	->search( 'Parks in Seattle' );
```

### Customizing the Iframe

[](#customizing-the-iframe)

```
$url    = $client->place( 'ChIJN1t_tDeuEmsRUsoyG83frY4' );
$iframe = $client->generate_iframe( $url, [
	'width'           => '100%',
	'height'          => '450',
	'class'           => 'google-map',
	'id'              => 'location-map',
	'style'           => 'border: 2px solid #ccc;',
	'loading'         => 'lazy',
	'allowfullscreen' => true
] );
```

### Handling Directions

[](#handling-directions)

```
// Configure options for directions
$client
	->set_mode( 'driving' )
	->set_avoid( [ 'tolls', 'highways' ] )
	->set_units( 'imperial' )
	->set_language( 'en' );

// Generate directions URL
$directions_url = $client->directions( 'Seattle, WA', 'Portland, OR' );
```

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

[](#api-methods)

### Client Methods

[](#client-methods)

- `place( $place_id, $options = [] )`: Generate URL for place embed
- `search( $query, $options = [] )`: Generate URL for search results
- `view( $latitude, $longitude, $options = [] )`: Generate URL for map view
- `directions( $origin, $destination, $options = [] )`: Generate URL for directions
- `streetview( $latitude, $longitude, $options = [] )`: Generate URL for street view
- `generate_iframe( $url, $attrs = [] )`: Generate complete iframe HTML

### Setters and Getters

[](#setters-and-getters)

- Travel Mode: `set_mode()`, `get_mode()`
- Map Type: `set_map_type()`, `get_map_type()`
- Units: `set_units()`, `get_units()`
- Avoid Routes: `set_avoid()`, `get_avoid()`
- Zoom Level: `set_zoom()`, `get_zoom()`
- Street View Camera:
    - `set_heading()`, `get_heading()`
    - `set_pitch()`, `get_pitch()`
    - `set_fov()`, `get_fov()`
- Localization:
    - `set_language()`, `get_language()`
    - `set_region()`, `get_region()`
- API Management:
    - `set_api_key()`, `get_api_key()`
    - `get_options()`, `reset_options()`

### Option Values

[](#option-values)

#### Travel Modes

[](#travel-modes)

- `driving`: Default driving directions
- `walking`: Walking directions
- `bicycling`: Bicycling directions
- `transit`: Public transit directions

#### Map Types

[](#map-types)

- `roadmap`: Default road map view
- `satellite`: Satellite imagery

#### Units

[](#units)

- `metric`: Kilometers and meters
- `imperial`: Miles and feet

#### Route Avoidance

[](#route-avoidance)

- `tolls`: Avoid toll roads
- `highways`: Avoid highways
- `ferries`: Avoid ferries

Use Cases
---------

[](#use-cases)

- **Business Locations**: Display store or office locations
- **Event Maps**: Show event venues and directions
- **Property Listings**: Display real estate locations
- **Travel Planning**: Show routes and destinations
- **Location Discovery**: Embed searchable maps
- **Virtual Tours**: Street view integration
- **Contact Pages**: Display business locations
- **Directory Listings**: Show multiple locations
- **Travel Guides**: Display tourist destinations
- **Store Locators**: Help customers find 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-maps-embed)
- [Issue Tracker](https://github.com/arraypress/google-maps-embed/issues)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity4

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

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/arraypress-google-maps-embed/health.svg)](https://phpackages.com/packages/arraypress-google-maps-embed)
```

###  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)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

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

PHP wrapper for the Meilisearch API

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

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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