CodeIgniter Forums

Full Version: Calculate all locations distance
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I have project named GPS Tracker
The one hundred device is active in my project
Each device send 24000 location to my server
In continue,i need calculate distance this locations for each device and save it
But number of records is high and if i use FOR statement for iterate array and calculate distance,the CPU maybe down
I try calculate distance between location when device send to server but locations is irregular and i cannot calculate exact distance
So i have to calculate distance after receive locations and insert into database and sort it and calculate distance

My code is :
PHP Code:
$this->db->order_by('time','ASC');
        
$this->db->where('device_id',$device_id);
        
$this->db->where('date',$date);
        
$locations $this->db->get('location')->result_array();

        
$last_location  =   '';
        
$distance       =   0;

        foreach (
$locations as $location) {

            if (
$last_location != '') {

                
$temp distance($last_location['latitude'],$last_location['longitude'],$location['latitude'],$location['longitude'],'m');

                if (!
is_nan($temp))
                    
$distance += $temp;

            }

            
$last_location $location;

        } 

Please suggest solution for me
Thanks