定制 cslash/laravel-geoname 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cslash/laravel-geoname

最新稳定版本:1.0.0

Composer 安装命令:

composer require cslash/laravel-geoname

包简介

Generate location labels like FR-WEST from IP addresses in Laravel.

README 文档

README

Latest Version on Packagist

Laravel GeoName is a lightweight package that generates location labels (e.g., FR-WEST, US-CENTRAL) from IP addresses or geographic coordinates. It's built on top of stevebauman/location to provide regional resolution.

Requirements

  • PHP 8.2 or higher
  • Laravel 10.0 or higher

Installation

You can install the package via composer:

composer require cslash/laravel-geo-name

The package will automatically register its service provider and facade.

Optionally, you can publish the config file:

php artisan vendor:publish --tag="geoname-config"

Usage

Using the Facade

The GeoName facade provides a simple interface to resolve location labels.

From Current Request

Automatically detect the user's IP address from the current request:

use Cslash\GeoName\Facades\GeoName;

$label = GeoName::fromRequest(); 
// Returns something like "FR-NORTH" or "US-WEST"

From a Specific IP

use Cslash\GeoName\Facades\GeoName;

$label = GeoName::fromIp('8.8.8.8');

From GeoContext

If you already have coordinates or region data, you can use a GeoContext object:

use Cslash\GeoName\Data\GeoContext;
use Cslash\GeoName\Facades\GeoName;

$context = new GeoContext(
    countryCode: 'FR',
    regionName: 'Brittany',
    regionCode: 'BRE',
    latitude: 48.1173,
    longitude: -1.6778
);

$label = GeoName::fromContext($context); // "FR-WEST"

Configuration

The config/geoname.php file allows you to customize fallbacks and region mappings:

return [
    'fallback' => 'XX-UNKNOWN', // Returned when IP location cannot be determined
    'unknown_zone' => 'UNKNOWN', // Returned when coordinates are missing for generic resolution

    'countries' => [
        'FR' => [
            'thresholds' => [47.5, 44.5, -0.5, 4.5], // north, south, west, east
            'region_map' => [
                'BRE' => 'WEST',
                'NOR' => 'WEST',
                // ...
            ],
        ],
    ],
];

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固