vpro/geo-calculator 问题修复 & 功能扩展

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

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

vpro/geo-calculator

Composer 安装命令:

composer require vpro/geo-calculator

包简介

A PHP package for calculating geographical distances

README 文档

README

Latest Version on Packagist Tests Total Downloads License

A PHP package for calculating geographic distances using the Haversine formula. Perfect for applications needing to determine distances between coordinates or check if locations are within a specific radius.

Features

  • 🌍 Calculate distances between geographic coordinates
  • 📏 Support for both kilometers and miles
  • 🎯 Check if points are within a given radius
  • 🔄 Convert between different distance units
  • 💪 Strong typing with PHP 7.4+ support
  • 🧪 Comprehensive test suite

Installation

You can install the package via composer:

composer require vpro/geo-calculator

Usage

Basic Distance Calculation

use GeoCalculator\DistanceCalculator;

$calculator = new DistanceCalculator();

// Calculate distance between New York and London
$distance = $calculator->calculateDistance(
    40.7128, -74.0060,  // New York coordinates
    51.5074, -0.1278    // London coordinates
);

echo "Distance: " . round($distance, 2) . " km";

Check if Point is Within Radius

// Check if location is within 100km radius
$isNearby = $calculator->isWithinRadius(
    40.7128, -74.0060,  // Center point
    40.7614, -73.9776,  // Point to check
    100,                // Radius
    'km'                // Unit ('km' or 'mi')
);

if ($isNearby) {
    echo "Location is within radius";
}

Convert Between Units

// Convert 100 kilometers to miles
$miles = $calculator->convertDistance(
    100,    // Distance
    'km',   // From unit
    'mi'    // To unit
);

echo "100 km = " . round($miles, 2) . " miles";

API Reference

calculateDistance()

Calculate the distance between two geographic points.

public function calculateDistance(
    float $lat1,
    float $lon1,
    float $lat2,
    float $lon2,
    string $unit = 'km'
): float

Parameters:

  • $lat1: Latitude of first point in degrees
  • $lon1: Longitude of first point in degrees
  • $lat2: Latitude of second point in degrees
  • $lon2: Longitude of second point in degrees
  • $unit: Unit of measurement ('km' or 'mi', defaults to 'km')

isWithinRadius()

Check if a point is within a specified radius of another point.

public function isWithinRadius(
    float $lat1,
    float $lon1,
    float $lat2,
    float $lon2,
    float $radius,
    string $unit = 'km'
): bool

Parameters:

  • $lat1: Latitude of center point in degrees
  • $lon1: Longitude of center point in degrees
  • $lat2: Latitude of point to check in degrees
  • $lon2: Longitude of point to check in degrees
  • $radius: Radius to check within
  • $unit: Unit of measurement ('km' or 'mi', defaults to 'km')

convertDistance()

Convert distances between different units.

public function convertDistance(
    float $distance,
    string $from,
    string $to
): float

Parameters:

  • $distance: Distance to convert
  • $from: Original unit ('km' or 'mi')
  • $to: Target unit ('km' or 'mi')

Testing

composer test

Contributing

Please see CONTRIBUTING.md for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Security

If you discover any security-related issues, please email your.email@example.com instead of using the issue tracker.

Credits

License

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

vpro/geo-calculator 适用场景与选型建议

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

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

围绕 vpro/geo-calculator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-30