sysborg/gmaps-laravel 问题修复 & 功能扩展

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

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

sysborg/gmaps-laravel

Composer 安装命令:

composer require sysborg/gmaps-laravel

包简介

Google Maps API package for Laravel using Ports and Adapters architecture

README 文档

README

A Google Maps API package for Laravel built on Ports and Adapters (Hexagonal Architecture) — clean, testable, and designed to grow with your needs.

PHP Laravel License Tests

Why this package?

Most Google Maps packages for Laravel expose raw arrays and mix API calls directly into your business logic. This package takes a different approach:

  • Ports and Adapters — your domain code never talks to Google directly; it depends on interfaces
  • Typed DTOsreadonly classes with full IDE autocomplete, no more guessing array keys
  • Built-in cache strategy — configurable TTL per use case to save money on API calls
  • Facade + DI — use whichever style fits your team

Installation

composer require sysborg/gmaps-laravel

Publish the config:

php artisan vendor:publish --provider="Sysborg\GmapsLaravel\GmapsServiceProvider" --tag="gmaps-config"

Add your API key to .env:

GOOGLE_MAPS_API_KEY=your_key_here

Make sure the Places API is enabled in your Google Cloud Console.

Usage

Nearby Places Search

Find all locations within a radius from a geographic point.

Via Facade:

use Sysborg\GmapsLaravel\Facades\GMap;
use Sysborg\GmapsLaravel\DTOs\Coordinate;

$response = GMap::nearbySearch(
    coordinate: new Coordinate(-23.5505, -46.6333),
    radius:     1500,           // meters
    type:       'restaurant',   // optional
    keyword:    'pizza',        // optional
);

foreach ($response->places as $place) {
    echo $place->name;           // "Pizzaria Italia"
    echo $place->vicinity;       // "Rua Augusta, 100"
    echo $place->rating;         // 4.5
    echo $place->location->latitude;
    echo $place->location->longitude;
}

if ($response->hasNextPage()) {
    // fetch next page using $response->nextPageToken
}

Via Dependency Injection:

use Sysborg\GmapsLaravel\UseCases\Places\NearbySearchUseCase;
use Sysborg\GmapsLaravel\DTOs\Coordinate;
use Sysborg\GmapsLaravel\DTOs\Places\NearbySearchRequest;

class FindNearbyRestaurantsAction
{
    public function __construct(private readonly NearbySearchUseCase $useCase) {}

    public function handle(float $lat, float $lng): array
    {
        $response = $this->useCase->execute(new NearbySearchRequest(
            coordinate: new Coordinate($lat, $lng),
            radius:     1500,
            type:       'restaurant',
        ));

        return $response->toArray();
    }
}

Cache Strategy

Every API call is cached by default. The cache key is a deterministic hash of all request parameters — same input always hits the cache.

# Toggle cache on/off
GOOGLE_MAPS_CACHE_ENABLED=true

# Use any Laravel cache driver
GOOGLE_MAPS_CACHE_DRIVER=redis

# TTL per use case (seconds)
GOOGLE_MAPS_CACHE_NEARBY_TTL=3600

Full config reference at config/gmaps.php.

Architecture

src/
├── Contracts/          ← Ports (pure PHP interfaces, zero framework imports)
│   ├── Cache/CachePort.php
│   ├── Http/HttpClientPort.php
│   └── Places/PlacesPort.php
├── DTOs/               ← Immutable readonly value objects
│   ├── Coordinate.php
│   └── Places/  NearbySearchRequest, PlaceResult, NearbySearchResponse
├── UseCases/           ← Application layer (depends only on Ports + DTOs)
│   └── Places/NearbySearchUseCase.php
├── Adapters/           ← Infrastructure (implements Ports using Laravel/Guzzle)
│   ├── Cache/LaravelCacheAdapter.php
│   ├── Http/LaravelHttpAdapter.php
│   └── Places/GooglePlacesAdapter.php
├── Facades/GMap.php
└── GmapsServiceProvider.php

Testing

composer install
./vendor/bin/phpunit

All tests use Http::fake() — no real API calls are made.

OK (11 tests, 30 assertions)

Currently Implemented

Feature Status
Places — Nearby Search
Cache with TTL per use case
Facade + DI integration
Typed DTOs (readonly)
PHPUnit tests with Http::fake()

Roadmap — Have a need? Open an issue!

This package is built to grow. The architecture makes it straightforward to add new APIs without touching existing code. If you need any of the below — or something not listed — open an issue and describe your use case. Contributions are welcome.

Feature Notes
Places — Text Search Search by keyword anywhere
Places — Place Details Full details by place_id
Places — Autocomplete For address/search inputs
Geocoding API Address ↔ coordinates
Reverse Geocoding Coordinates → formatted address
Directions API Routes with waypoints
Distance Matrix Multi-origin/destination travel time
Static Maps Generate map image URLs
Elevation API Altitude for coordinates
Time Zone API Timezone from coordinates
Roads API Snap-to-road, speed limits
Pagination helper Auto-fetch next pages
Multi-page collector Merge all paginated results automatically

Have a specific need? Open an issue describing what you need and how you plan to use it. The more context you give, the faster it gets implemented.

Contributing

  1. Fork the repository
  2. Create a branch: git checkout -b feat/your-feature
  3. Follow the existing patterns — one port, one adapter, one use case (see docs/plan/architecture.md)
  4. Write tests with Http::fake()
  5. Open a PR

Support the project

If this package saves you time or reduces your Google Maps API costs, consider buying a coffee. It helps keep this maintained and motivates new features to be added.

Buy Me a Coffee

License

MIT © Anderson Arruda

sysborg/gmaps-laravel 适用场景与选型建议

sysborg/gmaps-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 sysborg/gmaps-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-01