{"id":23709525,"url":"https://github.com/arraypress/geodistance","last_synced_at":"2025-10-10T14:38:12.975Z","repository":{"id":268391414,"uuid":"903829874","full_name":"arraypress/geodistance","owner":"arraypress","description":"A PHP utility class for calculating geographical distances between coordinates using the Haversine formula","archived":false,"fork":false,"pushed_at":"2025-02-15T20:31:01.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-02T17:32:13.412Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arraypress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-15T17:03:00.000Z","updated_at":"2025-02-15T20:31:05.000Z","dependencies_parsed_at":"2024-12-16T13:54:34.540Z","dependency_job_id":"8f521794-ccb7-43ca-9556-8991ce02b028","html_url":"https://github.com/arraypress/geodistance","commit_stats":null,"previous_names":["arraypress/geodistance"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arraypress/geodistance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fgeodistance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fgeodistance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fgeodistance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fgeodistance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arraypress","download_url":"https://codeload.github.com/arraypress/geodistance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fgeodistance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004177,"owners_count":26083688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-30T18:56:48.785Z","updated_at":"2025-10-10T14:38:12.943Z","avatar_url":"https://github.com/arraypress.png","language":"PHP","readme":"# ArrayPress GeoDistance\n\nA powerful PHP utility class for calculating geographical distances between coordinates using the Haversine formula. This library provides a clean, intuitive interface for accurate distance calculations in both miles and kilometers, with special integration for WordPress environments.\n\n## Features\n\n- 🌍 **Multi-Unit Support**: Calculate distances in miles or kilometers\n- 🎯 **Precision**: Results rounded to 2 decimal places for practical use\n- 🛡️ **Input Validation**: Comprehensive coordinate and unit validation\n- 📐 **Haversine Formula**: Accurate great-circle distance calculations\n- 🔒 **Type Safety**: Full type hinting and return type declarations\n- ⚡ **Simple Interface**: Easy to understand and implement\n- 🔄 **WordPress Integration**: Native WP_Error support when in WordPress environment\n- 🚫 **Error Handling**: Flexible error handling for both WordPress and standalone use\n\n## Requirements\n\n- PHP 7.4 or later\n- WordPress\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require arraypress/geodistance\n```\n\n## Basic Usage\n\n```php\nuse ArrayPress\\Utils\\Math\\GeoDistance;\n\n// New York coordinates\n$pointA = [ 'latitude' =\u003e 40.7128, 'longitude' =\u003e -74.0060 ];\n\n// London coordinates\n$pointB = [ 'latitude' =\u003e 51.5074, 'longitude' =\u003e -0.1278 ];\n\n// Initialize calculator\n$calculator = new GeoDistance( $pointA, $pointB );\n\n$distance = $calculator-\u003eget_distance();\nif ( is_wp_error( $distance ) ) {\n    echo $distance-\u003eget_error_message();\n} else {\n    echo \"Distance: $distance {$calculator-\u003eget_unit()}\";\n}\n```\n\n## Point Management\n\n### Getting Points\n\n```php\n// Get current coordinates\n$pointA = $calculator-\u003eget_point_a();\n$pointB = $calculator-\u003eget_point_b();\n```\n\n### Setting Points\n\n```php\n// WordPress Environment\n$result = $calculator-\u003eset_point_a([\n    'latitude'  =\u003e 35.6762,\n    'longitude' =\u003e 139.6503\n]);\n\nif ( is_wp_error( $result ) ) {\n    echo $result-\u003eget_error_message();\n}\n```\n\n### Checking if a Point is Within Radius\n\n```php\n// Central Park, New York\n$centralPoint = [ 'latitude' =\u003e 40.7829, 'longitude' =\u003e -73.9654 ];\n\n// Times Square coordinates\n$targetPoint = [ 'latitude' =\u003e 40.7580, 'longitude' =\u003e -73.9855 ];\n\n// Initialize calculator with central point\n$calculator = new GeoDistance( $centralPoint, $targetPoint );\n\n// WordPress Environment\n$radius = 2; // 2 miles radius\n$isWithin = $calculator-\u003eis_within_radius( $targetPoint, $radius );\nif ( is_wp_error( $isWithin ) ) {\n    echo $isWithin-\u003eget_error_message();\n} else {\n    echo $isWithin ? \"Location is within {$radius} {$calculator-\u003eget_unit()} radius\" : \"Location is outside radius\";\n}\n```\n\n## Unit Management\n\n### Getting and Setting Units\n\n```php\n// Get current unit\n$currentUnit = $calculator-\u003eget_unit();\n\n// WordPress Environment\n$result = $calculator-\u003eset_unit( 'km' );\nif ( is_wp_error( $result ) ) {\n    echo $result-\u003eget_error_message();\n}\n```\n\n## Error Handling\n\n### WordPress Environment\n\n```php\n// Check for errors using WP_Error\n$calculator = new GeoDistance( $pointA, $pointB );\n\n$result = $calculator-\u003eset_unit('invalid_unit');\nif ( is_wp_error( $result ) ) {\n    echo $result-\u003eget_error_message();\n    echo $result-\u003eget_error_code();\n}\n\n// Get the last error\n$lastError = $calculator-\u003eget_last_error();\nif ( $lastError instanceof WP_Error ) {\n    echo $lastError-\u003eget_error_message();\n}\n```\n\n## Error Codes\n\nThe library uses the following error codes when in a WordPress environment:\n\n- `invalid_coordinates`: Missing latitude or longitude keys\n- `invalid_latitude`: Latitude value out of range (-90 to 90)\n- `invalid_longitude`: Longitude value out of range (-180 to 180)\n- `invalid_unit`: Unsupported unit of measurement\n- `calculation_error`: Error during distance calculation\n\n## Use Cases\n\n- Distance Calculation: Calculate distances between geographical points\n- Location-Based Services: Determine proximity between locations\n- Travel Applications: Calculate travel distances\n- Geofencing: Determine if points are within specific distances\n- Delivery Services: Calculate shipping distances and zones\n- WordPress Integration: Seamless integration with WordPress applications\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the GPL-2.0-or-later License.\n\n## Support\n\n- [Documentation](https://github.com/arraypress/geodistance)\n- [Issue Tracker](https://github.com/arraypress/geodistance/issues)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fgeodistance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farraypress%2Fgeodistance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fgeodistance/lists"}