0

I have stored latitude and longitude again each Company's address in database. I have to show those Company record that comes under certain miles.

For example:

I search on City,State,Country and get the latitude and longitude using Google Map API. Then I get the distance using below code latitude longitude by adding subtracting.

$difference = 0.07;
$distance=$distanceKilometers!=0?ceil($this->miles2kms($distanceKilometers)/111):0;
latitude_from = floatval($lat) - $difference - $distance;
$latitude_to = floatval($lat) + $difference + $distance;
$longitude_from = floatval($lng) - $difference - $distance;
$longitude_to = floatval($lng) + $difference + $distance;

It does not work for me as It show lot of company records that does not come under N miles.

Could any one help me on this to get fix this issue? as I'm trying to fix since last 2 days and have tried many solutions available on different forums

  • Google "Haversine" or "Vincenty" – Mark Baker Oct 14 '14 at 10:16
  • possible duplicate of [Return Nearest Place available to Users location using Latitude-Longitude?](http://stackoverflow.com/questions/13493259/return-nearest-place-available-to-users-location-using-latitude-longitude) – david strachan Oct 14 '14 at 17:26
  • Mark and David, I tried Havershine too. In mysql it works fine but when I get lat long in result set and put it in maps.google.com it. Both shows different result. Like I want to get all the customers in 20 miles of Chichago IL using havershine. Mysql result shows 19.99 distance and same record with lat lon in maps.google.com show 22.2 miles. – Mubashar Ali Oct 15 '14 at 12:39

0 Answers0