I have designed the way of getting the latitudes and longitudes of a location. but how can I get the distance between that location and another location. I am using LARAVEL. thanks a lot.
Asked
Active
Viewed 2,313 times
-1
-
1Where's the problem? How is this related to Lavarel? Are both locations stored in a database and you want to receive the distance directly from the database? – Nico Haase Feb 07 '18 at 14:36
-
Actually yes, both locations are stored in the database and I want to get the distance directly from the database. – Okoye Kenneth Feb 07 '18 at 16:34
-
Then you probably need https://stackoverflow.com/questions/1006654/fastest-way-to-find-distance-between-two-lat-long-points – Nico Haase Feb 07 '18 at 19:49
1 Answers
1
This isn't a Laravel problem, it's a PHP problem. You have several options.
1. Use Google's Maps API:
https://developers.google.com/maps/documentation/distance-matrix/
This is more designed for direction information however.
2. Use GeoDistance:
https://github.com/0x13a/geodistance-php
This will give you "straight line" distance if that is what you are looking for. The above link provides details on how to install using Composer. From there you will have to add the package to your app/config.php under service providers and I would also recommend creating an alias for it in the same file.

Luke
- 943
- 6
- 12