0

I'm attempting to create an app that will let the user know which 5 or so of our 1,000+ locations he is closest to. I've looked through the Places docs (since Places appears to provide similar functionality), but have not found exactly what I'm looking for, or if I have, I haven't recognized it as such. I assume I'd have to pass the user's current location, along with a list of all of our installation locations, unless there's a way to have Google persist our installation locations which I could reference with each call. If anyone can point me in the right direction I'd appreciate it.

Thanks.

1

1 Answer 1

1

If you are only interested in a crow flies type closest then you don't even need maps at all.

You just need the long lats of the position of the user and of the various offices and do a straight forward distance calculation between them.

          $sql = "SELECT *,(((acos(sin((".$latitude."*pi()/180)) * sin((`Latitude`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`Latitude`*pi()/180)) * cos(((".$longitude."- `Longitude`)*pi()/180))))*180/pi())*60*1.1515) as distance FROM `MyTable` WHERE distance <= ".$distance.";//** Miles **//

That's a sql string to get all within a certain distance.

To get the five closest you would simply have an 'order by' and 'top 5'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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