java - search restaurant based on current geolocation -
i have database of restaurants exact address , when user search restaurant mobile device want show him restaurant in the order of distance current location restaurant close comes first in result. best way this?
you can use called haversine formula.
the below example php/mysql query still need.
$sql = "select *, ( 3959 * acos( cos( radians(" . $lat . ") ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(" . $lng . ") ) + sin( radians(" . $lat . ") ) * sin( radians( lat ) ) ) ) distance your_table having distance < 5";
where $lat
, $lng
coordinates of point, , lat/lng table columns. above list locations within 5 nm range. replace 3959
6371
change kilometers.
this link useful: https://developers.google.com/maps/articles/phpsqlsearch_v3
you can add order by
clause order results distance
.
Comments
Post a Comment