maarheeze/geocode-laravel 问题修复 & 功能扩展

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

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

maarheeze/geocode-laravel

Composer 安装命令:

composer require maarheeze/geocode-laravel

包简介

laravel integration for maarheeze/geocode

README 文档

README

Laravel integration for maarheeze/geocode.

This package wires the tiny, typed geocode library into Laravel: it binds the Geocode service in the container from config, ships a facade, and an optional database cache so repeated lookups don't hit the Google Maps API again.

Installation

composer require maarheeze/geocode-laravel

The package auto-registers via Laravel's package discovery, but make sure you run the migrations if you enable caching.

Configuration

Set your Google Maps API key:

GEOCODE_GOOGLE_MAPS_API_KEY=your-key

And you might want to override these default settings:

GEOCODE_CACHE_ENABLED=true
GEOCODE_CACHE_TABLE=geocode_cache

Usage

The Maarheeze\Geocode\Geocode contract is bound in the container, so inject it anywhere:

use Maarheeze\Geocode\Geocode;

class StoreController
{
    public function __construct(
        private readonly Geocode $geocode,
    ) {
    }

    public function show(): void
    {
        $coordinates = $this->geocode->getCoordinatesForAddress('Stationsstraat 1, Maarheeze');

        if ($coordinates !== null) {
            // $coordinates->latitude, $coordinates->longitude
        }
    }
}

Or via the facade:

use Maarheeze\Geocode\Laravel\Facades\Geocode;

$coordinates = Geocode::getCoordinatesForAddress('Stationsstraat 1, Maarheeze');

Distance

Coordinates can measure the great-circle distance to another Coordinates, returning a Distance you can read in meters or kilometers:

use Maarheeze\Geocode\Laravel\Facades\Geocode;

$eindhoven = Geocode::getCoordinatesForAddress('Eindhoven');
$maarheeze = Geocode::getCoordinatesForAddress('Maarheeze');

if ($eindhoven === null || $maarheeze === null) {
    // One of the addresses could not be resolved.
    return;
}

echo $eindhoven->distanceTo($maarheeze)->asKilometers(); // e.g. 18.7

Caching

When geocode.cache.enabled is true, the bound service is wrapped in a CachingGeocode decorator. Every resolved address is stored in the cache table (keyed by the address string) and subsequent lookups of the same address are served from the database without calling the API. Addresses that cannot be resolved are not cached. Caching is transparent — consumers keep using the same Geocode contract.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固