1

I have read a lot of about the best way to calculate the distance between two points position with Lat and Long (like Google Maps).

I have read this question very close to my own question that offers a MySQL Query Solution (link), I have read about GeoTools PHP (link GitHub) and about GeoTools Laravel (link GitHub) too.

In my own case, I have my current position like this:

37.754782, -122.425240

I have a lot of points stored in MySQL in the same format (about 1000K), and I need to obtain the 100 closest points to my current position (in meter or kilometers).

I would like to found a correct solution for Laravel REST API and MySQL, any ideas? Any suggest?

Thanks!!

Community
  • 1
  • 1
chemitaxis
  • 13,889
  • 17
  • 74
  • 125
  • I have use an javascript function to calculate distance between two lat,long points for google maps, i don't know about laravel, could it helps you? If so i share the code and you can translate it. – ericpap Nov 21 '14 at 13:07
  • No javascript supported, I need to return the id points computed, thanks! – chemitaxis Nov 21 '14 at 13:08
  • You can try to translate the javascript function into a mysql function and then using it in a SQL Query. It only use trigonometric funcion like Log and Sin. – ericpap Nov 21 '14 at 13:11
  • Thank you so much!! But I'm looking something specific,if you read my question carefully, you will se that I have solutions for my problem, I need a specific solution for Laravel REST API and MySQL – chemitaxis Nov 21 '14 at 13:13

2 Answers2

1

It would be easiest way to make query scope for a model where information about locations are stored (or write row query) which would use MySQL stored procedure that calculates the stuff (of using Sphinx search as in your example).

Than it is not so hard to create REST API in Laravel that will take point coordinates and use this scope to find and return results of closest POIs.

0

I am working on same thing and used POINT data type to store Lat Lng of location. Then I used distance_sphare function to get distance. Below is code for this function in mySQL 5.7

ST_DISTANCE_SPHERE(mysql_column_lat_lng, POINT($lat $lng))

This fuction will return distance in meter but problem is it will return displacement (the shortest distance between two points which is always a line).

Getting driving distance is not possible using above method, you will need to call google map api to get driving distance.

Umair Hamid
  • 3,509
  • 3
  • 23
  • 25