PHP query near the people and their distance implementation method, PHP query distance implementation
The example in this paper describes how to implement the people and their distances near PHP queries. Share to everyone for your reference, as follows:
<?php//gets the 4 points around the point $distance = 1;//Range (in units of kilometers) $lat = 113.873643; $lng = 22.573969;define (' Earth_radius ', 6371);//Earth radius, The average radius is 6371KM$DLNG = 2 * ASIN (SIN ($distance/(2 * earth_radius))/cos (Deg2rad ($lat))), $dlng = Rad2deg ($DLNG); $dlat = $dist Ance/earth_radius; $dlat = Rad2deg ($dlat); $squares = Array (' Left-top ' =>array (' lat ' = + $lat + $dlat, ' LNG ' =>$ lng-$dlng), ' Right-top ' =>array (' lat ' = + $lat + $dlat, ' lng ' = + $lng + $dlng), ' Left-bottom ' =>array (' Lat ' = ' $lat-$dlat, ' LNG ' + $lng-$dlng), ' Right-bottom ' =>array (' lat ' + $lat-$dlat, ' LNG ' + $LNG + $ DLNG));p rint_r ($squares [' left-top '] [' lat ']);//query matching records from the digital library $info_sql = "SELECT * from ' A ' where lat<>0 and lat& Gt {$squares [' right-bottom '] [' lat ']} and lat<{$squares [' left-top '] [' lat ']} and lng>{$squares [' left-top '] [' LNG '] } and lng<{$squares [' Right-bottom '] [' LNG ']} ";//get distance between two points function getdistancebetweenpointsnew ($latitude 1, $ Longitude1, $latitude 2, $longitude 2) {$theta = $longitude1-$longitude 2; $miles = (sin (Deg2rad ($latitude 1)) * Sin (Deg2rad ($latitude 2)) + (cos (Deg2rad ($latitude 1)) * cos (Deg2rad ($latitude 2)) * Cos (Deg2rad ($theta))); $miles = ACOs ($miles); $miles = Rad2deg ($miles); $miles = $miles * 60 * 1.1515; $feet = $miles * 5280; $yards = $feet/3; $kilometers = $miles * 1.609344; $meters = $kilometers * 1000; Return compact (' Miles ', ' feet ', ' yards ', ' kilometers ', ' meters '); } $point 1 = array (' lat ' = = 40.770623, ' long ' = -73.964367); $point 2 = Array (' lat ' = = 40.758224, ' long ' = 73.9 17404); $distance = getdistancebetweenpointsnew ($point 1[' lat '), $point 1[' long ', $point 2[' lat '], $point 2[' long ']); foreach ($distance as $unit = + $value) {echo $unit. ': '. Number_format ($value, 4). '
';}? >
More about PHP related content readers can view the topic: "PHP Math Skills Summary", "PHP array" operation Skills Daquan, "PHP Regular Expression Usage Summary", "Php+ajax Tips and Applications Summary", "PHP operation and operator Usage Summary", " PHP Network Programming Skills Summary, PHP Basic Grammar Introductory tutorial, PHP date and Time usage summary, PHP Object-oriented Programming primer tutorial, PHP string Usage Summary, PHP+MYSQL Database Operations primer, and A summary of common PHP database operation techniques
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1125875.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125875.html techarticle PHP Query near the people and their distance implementation method, PHP query distance implementation of this article describes the PHP query near the people and their distance implementation method. Share to everyone for your reference, specific ...