Giter Site home page Giter Site logo

karam-mustafa / laravel-geographical-calculator Goto Github PK

View Code? Open in Web Editor NEW
408.0 6.0 24.0 490 KB

laravel package helps you to implement geographical calculation, with several algorithms that help you deal with coordinates and distances.

License: MIT License

PHP 100.00%
laravel package laravel-package laravel-geolocation geolocation geogra geographical-calculator geometry geocoder geocoder-library

laravel-geographical-calculator's Introduction

logo

Geographical Calculator

License PHP Composer Check & fix styling Run tests Code Quality

Geographical Calculator was developed for laravel 5.8+ to help you to implement geographical calculation, with With several algorithms that help you deal with coordinates.

Installation

1 - Dependency

The first step is using composer to install the package and automatically update your composer.json file, you can do this by running:

composer require kmlaravel/laravel-geographical-calculator
2 - Copy the package providers to your local config with the publish command, this will publish the config:
php artisan geo:install

Features

config options

add your custom units,keys ..etc.

    /*
    |--------------------------------------------------------------------------
    | units values
    |--------------------------------------------------------------------------
    | your custom units, the initial units its convert from a mile to any value
    | (1.609344) is the conversion factor from a mile to a kilometer
    */
    'units' => [
        'mile' => 1,
        'km' => 1.609344,
        'm' => (1.609344 * 1000),
        'cm' => (1.609344 * 100),
        'mm' => (1.609344 * 1000 * 1000),
    ],

    /*
    |--------------------------------------------------------------------------
    | distance_key_prefix
    |--------------------------------------------------------------------------
    | if you declared more than tow points to resolve their distance,
    | you will see the result in the following format:
    | "1-2" => ["km" => "some result"],
    | "2-3" => ["km" => "some result"],
    | "3-4" => ["km" => "some result"],
    | and if you want to set any prefix before each index
    | you must change the below value to any value you want.
    |
    */
    'distance_key_prefix' => '',

Changelog

Please see the CHANGELOG for more information about what has changed or updated or added recently.

Security

If you discover any security related issues, please email them first to [email protected], if we do not fix it within a short period of time please open a new issue describing your problem.

Credits

karam mustafa

laravel-geographical-calculator's People

Contributors

iambateman avatar karam-mustafa avatar stylecibot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

laravel-geographical-calculator's Issues

Distance Measurement is Incorrect

This appears to measure the distance from one point to another in a straight line, can it measure the distance via a specific route on a map?

Figuring out distance discrepency

Been trying to figure this one out with the data at the bottom of the post.

If I sum all the distances together, I get about 24.5 miles

$setpoints = [];
foreach ($points as $point) {
    $setpoints[] = [$point->latitude, $point->longitude];
}

$distance =  \KMLaravel\GeographicalCalculator\Facade\GeoFacade::setPoint($setpoints[0])
    ->setPoints(array_slice($setpoints, 1))
    ->setOptions(['units' => ['mile']])
    ->getDistance();

$sumDistance = array_sum(array_column($distance,'mile'));

However if I find the distance between the first and last point, I get a distance of 53 miles. Likewise if I plug it into Google Maps it's around about the same.

$distance =  \KMLaravel\GeographicalCalculator\Facade\GeoFacade::setPoint([42.29587000,-83.85025000])
    ->setPoint([42.28291000, -84.90315000])
    ->setOptions(['units' => ['mile']])
    ->getDistance();

Why when adding the points individually would they come out different versus the first/last point? I can map all the in-between points which show a correct distance of around 55 miles. Unfortunately I can't just use first/last point as sometimes the coordinates will circle back on themselves as roads go.

image

 [
    [
      "42.29587000",
      "-83.85025000",
    ],
    [
      "42.29821800",
      "-83.85620000",
    ],
    [
      "42.29884300",
      "-83.87758000",
    ],
    [
      "42.29825000",
      "-83.89242600",
    ],
    [
      "42.29789400",
      "-83.89908600",
    ],
    [
      "42.29710800",
      "-83.92021000",
    ],
    [
      "42.29822500",
      "-83.93461600",
    ],
    [
      "42.29883000",
      "-83.94118000",
    ],
    [
      "42.29900000",
      "-83.96110000",
    ],
    [
      "42.29792400",
      "-83.97626500",
    ],
    [
      "42.29754600",
      "-83.98220000",
    ],
    [
      "42.29623000",
      "-84.00368000",
    ],
    [
      "42.29519000",
      "-84.01891000",
    ],
    [
      "42.29477700",
      "-84.02479000",
    ],
    [
      "42.29416300",
      "-84.04553000",
    ],
    [
      "42.29315000",
      "-84.06052000",
    ],
    [
      "42.29276700",
      "-84.06634000",
    ],
    [
      "42.29809000",
      "-84.10037000",
    ],
    [
      "42.29802000",
      "-84.10574000",
    ],
    [
      "42.29734800",
      "-84.12615000",
    ],
    [
      "42.29656000",
      "-84.14136000",
    ],
    [
      "42.29646700",
      "-84.14637000",
    ],
    [
      "42.29238500",
      "-84.16686000",
    ],
    [
      "42.29288500",
      "-84.18210000",
    ],
    [
      "42.29187800",
      "-84.20702000",
    ],
    [
      "42.29223000",
      "-84.22365000",
    ],
    [
      "42.29217500",
      "-84.22823000",
    ],
    [
      "42.29195000",
      "-84.24935000",
    ],
    [
      "42.29150800",
      "-84.26581600",
    ],
    [
      "42.29062700",
      "-84.26980000",
    ],
    [
      "42.28284500",
      "-84.28835000",
    ],
    [
      "42.28090000",
      "-84.30456000",
    ],
    [
      "42.27980000",
      "-84.30851000",
    ],
    [
      "42.27751500",
      "-84.32822400",
    ],
    [
      "42.27725600",
      "-84.34531000",
    ],
    [
      "42.27690000",
      "-84.36779000",
    ],
    [
      "42.27557400",
      "-84.38344000",
    ],
    [
      "42.27505000",
      "-84.38637000",
    ],
    [
      "42.27153000",
      "-84.40450000",
    ],
    [
      "42.27265000",
      "-84.42036000",
    ],
    [
      "42.27270500",
      "-84.42315000",
    ],
    [
      "42.26910400",
      "-84.44161000",
    ],
    [
      "42.26914200",
      "-84.45754000",
    ],
    [
      "42.26900000",
      "-84.46052600",
    ],
    [
      "42.26896000",
      "-84.47805000",
    ],
    [
      "42.26886400",
      "-84.49313000",
    ],
    [
      "42.26904700",
      "-84.49509000",
    ],
    [
      "42.26887500",
      "-84.53068000",
    ],
    [
      "42.26899300",
      "-84.53302000",
    ],
    [
      "42.26907700",
      "-84.55218000",
    ],
    [
      "42.26905400",
      "-84.56938000",
    ],
    [
      "42.26899700",
      "-84.57164000",
    ],
    [
      "42.26914600",
      "-84.59059000",
    ],
    [
      "42.26913000",
      "-84.60799400",
    ],
    [
      "42.26309200",
      "-84.62740000",
    ],
    [
      "42.26245500",
      "-84.64474500",
    ],
    [
      "42.26243200",
      "-84.64635500",
    ],
    [
      "42.26214000",
      "-84.66581000",
    ],
    [
      "42.26223800",
      "-84.68309000",
    ],
    [
      "42.26219600",
      "-84.68482000",
    ],
    [
      "42.26265000",
      "-84.70476000",
    ],
    [
      "42.26441600",
      "-84.72329000",
    ],
    [
      "42.26457200",
      "-84.72474000",
    ],
    [
      "42.26464000",
      "-84.74565000",
    ],
    [
      "42.26431300",
      "-84.76568000",
    ],
    [
      "42.26433000",
      "-84.76687000",
    ],
    [
      "42.28381300",
      "-84.79710000",
    ],
    [
      "42.28362700",
      "-84.81824500",
    ],
    [
      "42.28347800",
      "-84.83855400",
    ],
    [
      "42.28350400",
      "-84.83932000",
    ],
    [
      "42.28338200",
      "-84.86050400",
    ],
    [
      "42.28306000",
      "-84.88134000",
    ],
    [
      "42.28302800",
      "-84.88171000",
    ],
    [
      "42.28291000",
      "-84.90315000",
    ],
  ]

Package not compatible with Laravel 11

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires kmlaravel/laravel-geographical-calculator ^2.2 -> satisfiable by kmlaravel/laravel-geographical-calculator[v2.2.0].
    - Conclusion: don't install nunomaduro/collision v8.1.1 (conflict analysis result)
    - kmlaravel/laravel-geographical-calculator v2.2.0 requires phpunit/phpunit ^9.5 -> satisfiable by phpunit/phpunit[9.5.0, ..., 9.6.17].
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.6.17.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.6.11.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.27.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.24.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.23.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.22.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.18.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.14.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.9.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.7.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.5.
    - nunomaduro/collision v8.1.0 conflicts with phpunit/phpunit 9.5.4.
    - Root composer.json requires nunomaduro/collision ^8.1 -> satisfiable by nunomaduro/collision[v8.1.0, v8.1.1].

When added to Laravel 11, which needs to have
"nunomaduro/collision": "^8.1",
"phpunit/phpunit": "^10.0"

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires kmlaravel/laravel-geographical-calculator ^2.2 -> satisfiable by kmlaravel/laravel-geographical-calculator[v2.2.0].
    - kmlaravel/laravel-geographical-calculator v2.2.0 requires phpunit/phpunit ^9.5 -> found phpunit/phpunit[9.5.0, ..., 9.6.17] but it conflicts with your root composer.json require (^10.0).

but the laravel-geographical-calculator is tied to "phpunit/phpunit": ^9.5

cannot install on laravel 10

getting the error :
ERROR There are no commands defined in the "geo" namespace.

when trying to run the publish commande

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.