function get_member_action(){ $lat = $_GET["lat"]; $lng = $_GET["lng"]; $dist = $_GET["dist"]; //$lat = "22.64609400"; //$lng = "114.11702000"; //$dist = 1000; //$sql = "select * from hzg_member where ((lat-22.64609400)*(lat-22.64609400)+(lng-114.11702000)*(lng-114.11702000)) < 0.0081 order by ((lat-22.64609400)*(lat-22.64609400)+(lng-114.11702000)*(lng-114.11702000)) asc"; $arc = $dist / 1000 * 0.009; //默認搜索範圍爲1000米 0.009度 $where = " ((lat-$lat)*(lat-$lat)+(lng-$lng)*(lng-$lng)) < $arc*$arc order by ((lat-$lat)*(lat-$lat)+(lng-$lng)*(lng-$lng)) asc"; $rows = $this->obj->DB_select_all("member", $where, "*"); $i = 1; echo "緯度:$lat,經度:$lng, 周圍".$dist."米的人共有: ".count($rows)." 人<br/>"; foreach($rows as $key => $v){ $dist = $this->getDistance($lat,$lng,$v["lat"],$v["lng"]); echo $i++." ".$v["username"]." uid:".$v["uid"]." 緯度:".$v["lat"].",經度:".$v["lng"]." 距離:".$dist." 米<br/>"; } } function getDistance($lat1, $lng1, $lat2, $lng2) { $earthRadius = 6367000; //approximate radius of earth in meters $lat1 = ($lat1 * pi() ) / 180; $lng1 = ($lng1 * pi() ) / 180; $lat2 = ($lat2 * pi() ) / 180; $lng2 = ($lng2 * pi() ) / 180; $calcLongitude = $lng2 - $lng1; $calcLatitude = $lat2 - $lat1; $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); $stepTwo = 2 * asin(min(1, sqrt($stepOne))); $calculatedDistance = $earthRadius * $stepTwo; return round($calculatedDistance); }