I am developing a backend for a taxi app in Laravel 5.

Up to now, served areas are defined by the admins but I would like to change the way it works. I would like each taxi driver to define their working areas setting up a starting point and a radius (thus creating a circular area) and the final area is calculated by considering all the circles and merging the ones overlapping into a bigger and unique area.

In fact, I need to tell users beforehand if their requests comes from a supported or unsupported area and, merging areas, it would be much easier to do it (for instance, using Polygons in MySQL).

How would you design such an algorithm, possibly using MySQL built-in geospatial functions? I can only think about Haversine formula and PHP Topology tools to make things easier.

Thanks :)

  • 1
    Its probably possible. Though, that in of itself doesn't make a good question. Could you describe any of the problems you are having with designing this? – user40980 Nov 16 '15 at 23:21
  • Thank you. I have commented with some ideas but, at the moment, I am a bit stuck on the design part. It seems that in PHP there are no techniques to do it. – Washery Nov 16 '15 at 23:33

Maybe in your case - having centers and radius would be easier, instead of combining the circles, just to check if the distance of the user to the centers of the drivers is less that the given radius. Something like:

SELECT * from drivers where ST_DISTANCE(drivers.center, POINT([user.lon],[user.lat])) < drivers.radius;
/* assuming drivers.center is of type POINT(), */
/*  This will return all drivers that can serve the user */

The only catch is that ST_DISTANCE returns the result in degrees (same units as the coordinates), so either it should be converted to miles/km etc or the radius should be converted to degrees.

Check also this https://gis.stackexchange.com/questions/31628/find-points-within-a-distance-using-mysql

  • Some time on but excellent answer :) – Birdy Nov 19 '16 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.