Welcome Guest, Not a member yet? Register   Sign In
Get distance of locations
#1

Hi
I have many locations(about 1000 location)
I need calculate distance between this location
My code is :
PHP Code:
function distance($lat1$lon1$lat2$lon2$unit) {

        
$theta $lon1 $lon2;
        
$dist sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
        
$dist acos($dist);
        
$dist rad2deg($dist);
        
$miles $dist 60 1.1515;
        
$unit strtoupper($unit);

        if (
strtolower($unit) == "k") {
            return (
$miles 1.609344);
        } else if (
$unit == "N") {
            return (
$miles 0.8684);
        } else {
            return 
$miles;
        }
    } 

I calculate distance between two location with foreach
PHP Code:
foreach($result as $row) {

            if (
$current != NULL) {
                
$distance += distance($current['latitude'],$current['longitude'],$row['latitude'],$row['longitude'],'k') ;
                
$current    =   $row;
            } else {
                
$current    =   $row;
            }

        } 

In each loop,i save previous location and get distance from their
But it is wrong
Does anybody can help me?
Reply


Messages In This Thread
Get distance of locations - by omid_student - 10-30-2018, 01:18 AM
RE: Get distance of locations - by Pertti - 10-30-2018, 01:54 AM
RE: Get distance of locations - by omid_student - 10-30-2018, 01:59 AM
RE: Get distance of locations - by Pertti - 10-30-2018, 03:16 AM
RE: Get distance of locations - by omid_student - 10-30-2018, 05:14 AM
RE: Get distance of locations - by Pertti - 10-30-2018, 05:44 AM
RE: Get distance of locations - by omid_student - 10-30-2018, 02:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB