Tuesday, 10 January 2017

how to get 20 KM area Result in php .

    $distance = (20);  // value is km convent 1 miles = 1.60934 km
    $radius = 6371;
       
        $maxlat =  $latitude + (($distance / $radius) * 180.0 / M_PI);
        $minlat =  $latitude - (($distance / $radius) * 180.0 / M_PI);

        $maxlng = $longitude + (($distance / $radius / cos($latitude * M_PI /180.0))  * 180.0 / M_PI);
        $minlng = $longitude - (($distance / $radius / cos($latitude * M_PI /180.0))  * 180.0 / M_PI);

Use Query--->>

SELECT * FROM table_name WHERE  latitude BETWEEN $minlat AND $maxlat AND longitude BETWEEN $minlng AND $maxlng

No comments:

Post a Comment