0

I'm developing a website and in the contacts page I need to assist the user to find the closest store and give the user directions to it on google maps!

The company has 4 stores in the city (and I have the latitudes & longitudes for all stores).

When the user presses a button I get the latitude & longitude of the user.

So far so good! Now I need to calculate which store is closest to user. How can I do this?

Backlin
  • 14,612
  • 2
  • 49
  • 81
E P
  • 389
  • 4
  • 16
  • Do you mean the actual formula? http://en.wikipedia.org/wiki/Great-circle_distance – rlb Mar 14 '13 at 08:49
  • Have you considered using the [Google Distance Matrix API](https://developers.google.com/maps/documentation/distancematrix/) to calculate the route and distance to each store and compare that? – RobG Mar 14 '13 at 10:33
  • @RobG no it's going to be to many request to send if they have more then 4 store! but tnx for the tips! – E P Mar 14 '13 at 12:11

1 Answers1

1

In terms of straight line distance you can make use of the Haversine formula that calculates the distance between two points each defined by a latitude and longitude

Haversine in PHP or Haversine in Python

Community
  • 1
  • 1
Conway Stern
  • 152
  • 2
  • 10