arraypress/google-address-validation
Composer 安装命令:
composer require arraypress/google-address-validation
包简介
A PHP library for integrating with the Google Address Validation API in WordPress, providing comprehensive address validation, standardization, and verification. Features WordPress transient caching and WP_Error support.
关键字:
README 文档
README
A PHP library for integrating with the Google Address Validation API in WordPress. This library provides robust address validation, standardization, and verification capabilities with support for WordPress transient caching and WP_Error handling.
Features
- ✅ Address Validation: Verify and standardize addresses globally
- 📊 Validation Scoring: Get numerical scores (0-100) and ratings for address quality
- 🏠 Detailed Components: Access all address components and metadata
- 📫 USPS Support: Enhanced validation for US addresses with USPS data
- 🌍 International: Support for addresses worldwide with region code handling
- 🔄 Response Parsing: Clean response object for easy data access
- ⚡ WordPress Integration: Native transient caching and WP_Error support
- 🛡️ Type Safety: Full type hinting and strict types
- 🏢 Business Detection: Identify business locations and PO boxes
- 📍 Geocoding: Get coordinates for validated addresses
- 🔍 Validation Details: Access validation status and issues
Requirements
- PHP 7.4 or later
- WordPress 5.0 or later
- Google Address Validation API key
Installation
Install via Composer:
composer require arraypress/google-address-validation
Basic Usage
use ArrayPress\Google\AddressValidation\Client; // Initialize client with your API key $client = new Client( 'your-google-api-key' ); // Validate an address $result = $client->validate( '1600 Amphitheatre Parkway, Mountain View, CA' ); if ( ! is_wp_error( $result ) ) { // Get validation score and rating $score = $result->get_score(); $rating = $result->get_rating(); echo "Validation Score: {$score}/100 ({$rating})\n"; // Check if address is verified if ( $result->is_verified() ) { // Get standardized address $address = $result->get_standardized_address(); echo "Formatted Address: {$address['formatted_address']}\n"; // Get coordinates if ( $geocode = $result->get_geocode() ) { echo "Latitude: {$geocode['latitude']}\n"; echo "Longitude: {$geocode['longitude']}\n"; } } }
Validation Scoring
The library provides a comprehensive scoring system to assess address quality:
$result = $client->validate( '1600 Amphitheatre Parkway, Mountain View, CA' ); if ( ! is_wp_error( $result ) ) { // Get numerical score (0-100) $score = $result->get_score(); // Get human-readable rating $rating = $result->get_rating(); // Returns: Excellent, Good, Fair, or Poor // Example score interpretation switch (true) { case $score >= 90: echo "Excellent - Highly reliable address\n"; break; case $score >= 75: echo "Good - Reliable address with minor issues\n"; break; case $score >= 50: echo "Fair - Address may need verification\n"; break; default: echo "Poor - Address needs significant verification\n"; } }
Score Components
The validation score considers multiple factors:
- Address completeness (30 points)
- Confirmed components (20 points)
- No inferred components (15 points)
- No replaced components (10 points)
- Geocoding data (10 points)
- Postal code presence (5 points)
- Precise location (5 points)
- USPS validation (5 bonus points for US addresses)
Extended Examples
USPS Validation for US Addresses
// Enable USPS validation for US addresses $result = $client->validate( '1600 Pennsylvania Avenue NW, Washington, DC 20500', 'US', true // Enable USPS validation ); if ( ! is_wp_error( $result ) ) { $usps_data = $result->get_usps_data(); // Access USPS-specific data }
Address Type Detection
$result = $client->validate( '123 Business Street, Anytown, USA' ); if ( ! is_wp_error( $result ) ) { if ( $result->is_residential() ) { echo "This is a residential address\n"; } elseif ( $result->is_po_box() ) { echo "This is a PO Box\n"; } else { echo "This is likely a commercial address\n"; } }
Working with Address Components
$result = $client->validate( '1600 Amphitheatre Parkway, Mountain View, CA' ); if ( ! is_wp_error( $result ) ) { $components = $result->get_standardized_address(); echo "Street: {$components['street_number']} {$components['street_name']}\n"; echo "City: {$components['locality']}\n"; echo "State: {$components['administrative_area']}\n"; echo "ZIP: {$components['postal_code']}\n"; echo "Country: {$components['country']}\n"; }
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->validate( '1600 Amphitheatre Parkway, Mountain View, CA' ); // Clear specific cache $client->clear_cache( 'validate_1600 Amphitheatre Parkway, Mountain View, CA' ); // Clear all validation caches $client->clear_cache();
API Methods
Client Methods
validate( $address, $region_code = '', $enable_usps = false, $previous_address = false): Validate an addressclear_cache( $identifier = null): Clear cached responses
Response Methods
Validation Methods
get_score(): Get numerical validation score (0-100)get_rating(): Get human-readable validation ratingcheck_validity(): Get detailed validation analysisis_fully_validated(): Check if address is completely validatedis_high_confidence(): Check if address has high confidence validationis_minimal_valid(): Check if address meets minimal validation requirementsis_standardized(): Check if address is in standard formatis_exact_match(): Check if address is an exact match without inferencesis_verification_needed(): Check if address needs additional verificationis_deliverable(): Check if address is deliverable (USPS data for US addresses)is_shippable(): Check if address is valid for shippingis_valid_landmark(): Check if address is a valid landmark/POIis_us_address(): Check if address is in the United Stateshas_minimal_components(): Check if address has required components
Address Properties
is_business(): Check if address is a business locationis_residential(): Check if address is residentialis_po_box(): Check if address is a PO Boxis_active(): Check if address is active (USPS)is_vacant(): Check if address is vacant (USPS)is_commercial_mail_receiver(): Check if address is a CMRA (USPS)
Basic Example
use ArrayPress\Google\AddressValidation\Client; // Initialize client $client = new Client( 'your-google-api-key' ); // Validate an address $result = $client->validate( '1600 Amphitheatre Parkway, Mountain View, CA' ); if ( ! is_wp_error( $result ) ) { // Get detailed validation status $validity = $result->check_validity(); if ( $validity['is_valid'] ) { echo "Confidence Level: {$validity['confidence_level']}\n"; // Check specific validation aspects if ( $result->is_high_confidence() ) { echo "High confidence validation\n"; } if ( $result->is_shippable() ) { echo "Valid shipping address\n"; } } else { echo "Validation Issues:\n"; foreach ( $validity['issues'] as $issue ) { echo "- $issue\n"; } } }
Use Cases
- Address Verification: Validate customer addresses with confidence scores
- Data Standardization: Standardize address data
- USPS Integration: Enhanced US address validation
- Fraud Prevention: Verify address authenticity
- International Support: Validate global addresses
- Business Verification: Identify business locations
- Data Quality: Assess and maintain address data quality with numerical metrics
- Location Services: Support location-based features
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-address-validation 适用场景与选型建议
arraypress/google-address-validation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 12 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geocoding」 「google-maps」 「wordpress」 「address-validation」 「address-components」 「address-parsing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/google-address-validation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/google-address-validation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/google-address-validation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
GISCO Geocoding Provider for Geocoder PHP.
Harness the power of the Google Autocomplete API inside Craft. Adds an autocomplete search box to Craft entries.
Laravel package that helps to use GoogleMaps
Laravel integration for Nominatim Geocoding API Client
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2024-12-17