google maps - List nearest Longitude/Latitude from array -
i have 2 variables define static longitude , latitude. want able define multi dimensional array holds following: id, longitude , latitude.
what want achieve - static longitude feed through loop of arrays , if finds within radius of 50 miles (or whatever), selects potential ones , lists them.
i not sure formula or algorithm can use check radius , bring nearest values.
please note: not using databases in example.
so far:
$mainlong = 57.7394571; $mainlat = -4.386997; $main = array( array("loc_1",57.7394571,-4.686997), array("loc_2",51.5286416,-0.1015987), array("loc_3",51.2715146,-0.3953564), array("loc_4",50.837418,-0.1061897) ); foreach ( $main $key => $value ) { if($value[1] == $mainlong){ print_r($value); } }
haversine formula help. here sample algorithm. can try out.
%% begin calculation r = 6371; % earth's radius in km delta_lat = locs{2}(1) - locs{1}(1); % difference in latitude delta_lon = locs{2}(2) - locs{1}(2); % difference in longitude = sin(delta_lat/2)^2 + cos(locs{1}(1)) * cos(locs{2}(1)) * ... sin(delta_lon/2)^2; c = 2 * atan2(sqrt(a), sqrt(1-a)); km = r * c; % distance in km %% convert result nautical miles , miles nmi = km * 0.539956803; % nautical miles mi = km * 0.621371192; % miles
Comments
Post a Comment