arraypress/google-maps-embed 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arraypress/google-maps-embed

Composer 安装命令:

composer require 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.

README 文档

README

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

  • 🗺️ 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

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

Installation

Install via Composer:

composer require arraypress/google-maps-embed

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

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

// 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

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

// 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

$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

// 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

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

  • 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

Travel Modes

  • driving: Default driving directions
  • walking: Walking directions
  • bicycling: Bicycling directions
  • transit: Public transit directions

Map Types

  • roadmap: Default road map view
  • satellite: Satellite imagery

Units

  • metric: Kilometers and meters
  • imperial: Miles and feet

Route Avoidance

  • tolls: Avoid toll roads
  • highways: Avoid highways
  • ferries: Avoid ferries

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

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

License

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

Support

arraypress/google-maps-embed 适用场景与选型建议

arraypress/google-maps-embed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「google-maps」 「wordpress」 「google-places」 「street-view」 「map-integration」 「maps-embed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 arraypress/google-maps-embed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 arraypress/google-maps-embed 我们能提供哪些服务?
定制开发 / 二次开发

基于 arraypress/google-maps-embed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2024-12-18